问题描述
我的后端代码使用Django Rest Framework,具体代码如下:
with open(results['filepath'],'rb') as target:
response = HttpResponse(target)
response['Content-Type'] = 'application/octet-stream'
filename = results['filename']
disposition = "attachment; filename*=UTF-8''{}".format(filename)
response["Content-disposition"] = disposition
return response
我的前端代码使用vue-element-admin,具体代码如下:
this.$axios.post(
`/api/v1/applications/pod-dlfiles/?cluster=${this.dialogFile.cluster}&name=${this.dialogFile.name}&ns=${this.dialogFile.namespace}&cr=${this.dialogFile.container}`,data
).then((res) => {
console.error('restest',res)
var fileURL = window.URL.createObjectURL(new Blob([res]))
var fileLink = document.createElement('a')
fileLink.href = fileURL
fileLink.setAttribute('download',`${this.dialogFile.name}` + '.txt')
document.body.appendChild(fileLink)
fileLink.click()
})
我打印了'res'的值,结果就是文件的内容。 没有其他属性。为什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)