Commit 170eb867 by 周田

fix:修复 http 响应头无法使用中文

parent 0614881a
......@@ -34,7 +34,7 @@ const downloadFile = () => {
const blob = new Blob([res.data], { type: "multipart/form-data" });
const link = document.createElement("a");
link.href = window.URL.createObjectURL(blob);
link.download = res.headers["filename"]
link.download = decodeURIComponent(res.headers["filename"]);
link.click();
});
console.log("downloadFile");
......
import os
import urllib.parse
from django.conf import settings
from django.http import FileResponse
from django.shortcuts import render
......@@ -42,18 +44,19 @@ def download(request):
protocol_name = request.GET.get('protocol_name')
version = request.GET.get('version')
print(protocol_name)
print(version)
file_path = os.path.join(settings.BASE_DIR, 'protocol_raw_files', protocol_name, version)
print(file_path)
for root, _, files in os.walk(file_path):
print(f"root ==> {root}")
file_path = os.path.join(root, files[1])
for file in files:
# if file != 'xdc.sqlite':
# continue
file_path = os.path.join(root, files[3])
# 适配中文
file_name = urllib.parse.quote(os.path.basename(file_path))
response = FileResponse(open(file_path, 'rb'))
response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path)
response['Content-Disposition'] = 'inline; filename=' + file_name
response['Content-Type'] = 'multipart/form-data'
response['filename'] = os.path.basename(file_path)
response['filename'] = file_name
return response
return Response(status=status.HTTP_200_OK)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment