【发布时间】:2023-02-01 01:39:44
【问题描述】:
请帮我下载存档。 我从后端得到这个 json。
{
"version": "1.1",
"content": {
"headers": [
{
"key": "Content-Length",
"value": [
"4838778"
]
},
{
"key": "Content-Disposition",
"value": [
"attachment; filename=Archive.zip"
]
},
{
"key": "Content-Type",
"value": [
"application/zip"
]
}
]
},
"statusCode": 200,
"reasonPhrase": "OK",
"headers": [],
"trailingHeaders": [],
"requestMessage": null,
"isSuccessStatusCode": true
}
我正在尝试像这样下载它。
function download(){
axios.defaults.responseType = 'blob'
axios.post('https://localhost:7120/api/Import/UploadFile', {
SipName: 'login',
SipPasw: "password"
})
.then((r)=>{
console.log(r)
var fileURL=window.URL.createObjectURL(new Blob([r.data]));
var fileLink=document.createElement('a');
fileLink.href=fileURL;
fileLink.setAttribute('download', "Archive.zip");
document.body.appendChild(fileLink);
fileLink.click();
})
.catch((e)=>{
console.log(e)
})
}
但是已下载损坏的存档。 在 JSON 中,可以看到那里累积了 4 兆字节,并下载了一个重达 332 字节的存档。
据我了解,我不是在下载我发送的存档,而是下载 zip 格式的传入 JSON。但是如何从答案中下载存档呢?
【问题讨论】:
标签: javascript vue.js