fix: file name incorrect when download file (#19183)

This commit is contained in:
非法操作
2025-04-30 22:47:59 +08:00
committed by GitHub
parent 349c3cf7b8
commit 1ca6dbcdc8
3 changed files with 6 additions and 4 deletions

View File

@@ -60,7 +60,7 @@ class ToolFileMessageTransformer:
mimetype = meta.get("mime_type", "application/octet-stream") mimetype = meta.get("mime_type", "application/octet-stream")
# get filename from meta # get filename from meta
filename = meta.get("file_name", None) filename = meta.get("filename", None)
# if message is str, encode it to bytes # if message is str, encode it to bytes
if not isinstance(message.message, ToolInvokeMessage.BlobMessage): if not isinstance(message.message, ToolInvokeMessage.BlobMessage):

View File

@@ -32,6 +32,7 @@ const FileImageItem = ({
}: FileImageItemProps) => { }: FileImageItemProps) => {
const { id, progress, base64Url, url, name } = file const { id, progress, base64Url, url, name } = file
const [imagePreviewUrl, setImagePreviewUrl] = useState('') const [imagePreviewUrl, setImagePreviewUrl] = useState('')
const download_url = url ? `${url}&as_attachment=true` : base64Url
return ( return (
<> <>
@@ -84,7 +85,7 @@ const FileImageItem = ({
className='absolute bottom-0.5 right-0.5 flex h-6 w-6 items-center justify-center rounded-lg bg-components-actionbar-bg shadow-md' className='absolute bottom-0.5 right-0.5 flex h-6 w-6 items-center justify-center rounded-lg bg-components-actionbar-bg shadow-md'
onClick={(e) => { onClick={(e) => {
e.stopPropagation() e.stopPropagation()
downloadFile(url || base64Url || '', name) downloadFile(download_url || '', name)
}} }}
> >
<RiDownloadLine className='h-4 w-4 text-text-tertiary' /> <RiDownloadLine className='h-4 w-4 text-text-tertiary' />

View File

@@ -45,6 +45,7 @@ const FileItem = ({
let tmp_preview_url = url || base64Url let tmp_preview_url = url || base64Url
if (!tmp_preview_url && file?.originalFile) if (!tmp_preview_url && file?.originalFile)
tmp_preview_url = URL.createObjectURL(file.originalFile.slice()).toString() tmp_preview_url = URL.createObjectURL(file.originalFile.slice()).toString()
const download_url = url ? `${url}&as_attachment=true` : base64Url
return ( return (
<> <>
@@ -93,13 +94,13 @@ const FileItem = ({
} }
</div> </div>
{ {
showDownloadAction && tmp_preview_url && ( showDownloadAction && download_url && (
<ActionButton <ActionButton
size='m' size='m'
className='absolute -right-1 -top-1 hidden group-hover/file-item:flex' className='absolute -right-1 -top-1 hidden group-hover/file-item:flex'
onClick={(e) => { onClick={(e) => {
e.stopPropagation() e.stopPropagation()
downloadFile(tmp_preview_url || '', name) downloadFile(download_url || '', name)
}} }}
> >
<RiDownloadLine className='h-3.5 w-3.5 text-text-tertiary' /> <RiDownloadLine className='h-3.5 w-3.5 text-text-tertiary' />