通过Axios从Django下载文件
我正在尝试使用Axios和Django从blob请求中获取文件名 Django的观点:通过Axios从Django下载文件,django,axios,Django,Axios,我正在尝试使用Axios和Django从blob请求中获取文件名 Django的观点: with open(full_file_path, 'rb') as f: response = HttpResponse(f, content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') file_expr = "filename*=utf-8''{}".fo
with open(full_file_path, 'rb') as f:
response = HttpResponse(f, content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
file_expr = "filename*=utf-8''{}".format(quote(file_name_with_ext))
response['Content-Disposition'] = 'attachment; {}'.format(file_expr)
return response
前端:
axios
.request({
url,
method,
responseType: 'blob',
})
.then(({ data }) => {
console.log(data);
const downloadUrl = window.URL.createObjectURL(new Blob([data]));
const link = document.createElement('a');
link.href = downloadUrl;
link.setAttribute('download', 'file.xlsx');
document.body.appendChild(link);
link.click();
link.remove();
});
但参数“data”不包含允许我获取文件名的标题
有什么解决办法吗?代替这个
。然后({data})=>{
使用这个:。然后(response=>{
而response.data
是您可以通过console.log(response.data);
希望它能帮助而不是
。然后({data})=>{
使用这个:。然后(response=>{
而response.data
是您可以通过console.log(response.data);
希望能有帮助