簡體   English   中英

是否可以在 iOS 上的 Edge 中下載 blob 文件?

[英]Is it possible to download a blob file in Edge on iOS?

我正在嘗試支持從 iOS 版 Edge 中的 API 下載文件。 該文件作為 blob 下載,我們已經有了在 Safari 和 Chrome 上下載的解決方案(分別使用createObjectUrlreadAsDataUrl ),但這些似乎都不適用於 iOS 上的 Edge。

我在網上找不到任何關於如何執行此操作的信息,甚至 FileReader 似乎也不支持它。

我嘗試使用在 iOS 上的 Chrome 和 iOS 上的 Safari 中一致工作的解決方案進行下載。

編輯:iOS 上的 Edge 使用 Safari 的渲染引擎,因此任何 IE11 或 Edge on Desktop 解決方案在這里都不起作用。

在 IE/Edge 瀏覽器中,您可以嘗試使用 window.navigator.msSaveOrOpenBlob 方法下載文件。 您可以查看這些文章: thread 1article 1 像這樣的代碼:

showFile(blob){
  // It is necessary to create a new blob object with mime-type explicitly set
  // otherwise only Chrome works like it should
  var newBlob = new Blob([blob], {type: "application/pdf"})

  // IE doesn't allow using a blob object directly as link href
  // instead it is necessary to use msSaveOrOpenBlob
  if (window.navigator && window.navigator.msSaveOrOpenBlob) {
    window.navigator.msSaveOrOpenBlob(newBlob);
    return;
  } 

  // For other browsers: 
  // Create a link pointing to the ObjectURL containing the blob.
  const data = window.URL.createObjectURL(newBlob);
  var link = document.createElement('a');
  link.href = data;
  link.download="file.pdf";
  link.click();
  setTimeout(function(){
    // For Firefox it is necessary to delay revoking the ObjectURL
    window.URL.revokeObjectURL(data);
  , 100}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM