问题描述
我正在使用以下命令将 zip 文件从我的 nodejs 服务器发送到浏览器
res.set("Content-Type","application/octet-stream");
res.set("Content-disposition",`attachment; filename="`+zip_name+`.zip"`);
res.set("Content-Length",zipBuff.length);
res.send(zipBuff);
然后我使用:
fetch("/my/url",{
method: "POST",body: formData,})
.then(response => {
return response.blob();
})
.then(response => {
const blob = new Blob([response],{type: 'application/zip'});
const downloadUrl = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = downloadUrl;
a.download = "blah.zip";
document.body.appendChild(a);
a.click();
});
我希望能够使用 zip_name
而不是 blah
作为文件名,但我不知道如何访问标题(在这种情况下为 Content-disposition
)回复 fetch
。
有人可以解释一下它是如何完成的吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)