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

后端 未结 1 1499
小蘑菇
小蘑菇 2021-02-20 05:30

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

1条回答
  •  悲&欢浪女
    2021-02-20 06:13

    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().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 = ;
        document.body.appendChild(a);
        a.click();
    
        setTimeout(() => {
          window.URL.revokeObjectURL(url);
          document.body.removeChild(a);
        }, 1000);
      })
    

    0 讨论(0)
提交回复
热议问题