【问题标题】:Open blob file stored in indexDB on ios/Ipad打开存储在 ios/Ipad 上 indexedDB 中的 blob 文件
【发布时间】: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);

我在 db 中有文件,比如 blob

接下来我想像这样保存它: 下载(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


    【解决方案1】:

    现在将数据存储为数组缓冲区,而不是 blob。

    【讨论】:

      猜你喜欢
      • 2011-03-17
      • 1970-01-01
      • 2011-03-17
      • 2019-04-04
      • 1970-01-01
      • 2021-05-06
      • 2016-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多