fix: The original document download file name is incorrect (#3542)

This commit is contained in:
shaohuzhang1 2025-07-09 22:32:40 +08:00 committed by GitHub
parent 7c47f4d0b3
commit 1611bc7f75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View File

@ -1,4 +1,5 @@
# coding=utf-8
import urllib
import uuid_utils.compat as uuid
from django.db.models import QuerySet
@ -94,9 +95,10 @@ class FileSerializer(serializers.Serializer):
raise NotFound404(404, _('File not found'))
file_type = file.file_name.split(".")[-1].lower()
content_type = mime_types.get(file_type, 'application/octet-stream')
encoded_filename = urllib.parse.quote(file.file_name)
headers = {
'Content-Type': content_type,
'Content-Disposition': f'{"inline" if file_type == "pdf" else "attachment"}; filename="{file.file_name}"'
'Content-Disposition': f'{"inline" if file_type == "pdf" else "attachment"}; filename={encoded_filename}'
}
return HttpResponse(
file.get_bytes(),

View File

@ -27,7 +27,7 @@
</div>
<div class="ml-8" v-else>
<a
:href="getFileUrl(item?.meta?.source_file_id)"
:href="getFileUrl(item?.meta?.source_file_id || item?.source_url)"
target="_blank"
class="ellipsis-1"
:title="item?.document_name?.trim()"