【发布时间】:2021-04-26 03:01:38
【问题描述】:
你好,我像这样使用 axios 下载文件。
return axios({
method: "get",
url: URL,
responseType: "blob",
})
.then((response) => {
return {
...val,
blob: response.data,
};
})
.catch((_) => {
onError(val);
});
之后我使用 Dexie 将其存储在 indexDB 中。
const { id } = dataToSave;
return db.files.put(dataToSave, id);
接下来我想像这样保存它: 下载(myBlob,标题,mimeType); 我尝试使用文件保护程序、downloadjs 或手动
const { title, blob, mimeType } = material;
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.style.display = "none";
a.href = url;
// the filename you want
a.download = title;
document.body.appendChild(a);
a.click();
setTimeout(() => {
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
}, 1000);
只有在我将文件下载到 blob(浏览器会话)后,它才会立即下载文件。
当我刷新页面时,我收到错误WebkitBlobResource:1。
任何问题的解决方法?下载文件(pdf、html)或在新标签或同一标签中打开。
【问题讨论】:
标签: javascript ios ipad safari indexeddb