Mobile Safari download issue : The operation couldn’t be completed. (webkitblobresource error 1.)

主宰稳场 提交于 2020-07-18 04:15:48

问题


My Angular application has a pdf download option. When i run my application in Iphone(IOS 12) Safari browser I get the following error message as shown in the image

How can i resolve it?

ios_safari_issue


回答1:


If you are injecting an ancor tag into DOM programmatically as your solution, make sure you do not clear that up too soon.

For me 100ms worked fine but since it's invisible either way I chose 1 second delay on clearing DOM up.

Example code:

this.fileApi.download(<your args>).subscribe((data: Blob) => {
    const url = window.URL.createObjectURL(data);
    const a = document.createElement('a');
    a.style.display = 'none';
    a.href = url;

    // the filename you want
    a.download = <your filename>;
    document.body.appendChild(a);
    a.click();

    setTimeout(() => {
      window.URL.revokeObjectURL(url);
      document.body.removeChild(a);
    }, 1000);
  })


来源:https://stackoverflow.com/questions/54339607/mobile-safari-download-issue-the-operation-couldn-t-be-completed-webkitblobr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!