Alternative for 'download' attribute in Safari/iOS

前端 未结 3 1024
栀梦
栀梦 2020-12-14 18:08

I have a blob created with a base64, and I need to make this data downloadable as a pdf.

I created this snippet:

    var blob = new Blob([byte]);
            


        
相关标签:
3条回答
  • 2020-12-14 18:48

    The "target" attribute in Safari seems to override the "download" attribute. Currently, as to my knowledge, there is no way to solve this. So I think you have to wait for the next Safari version (13) which will be out in a few months.

    0 讨论(0)
  • 2020-12-14 18:52

    I need to make this data downloadable as a pdf (...) in safari iOS

    SHORT ANSWER: you can't. Due this bug is impossible to download the file on safari iOS


    The alternative is to open the file on the browser with the proper mime type, so it can show its content (and the user can then manually download it if needed).

    Make sure to pass mime type when creating the Blob. reference

    var blob = new Blob([byte], {type: 'application/pdf'});
    

    Lastly, I'd strongly suggest you to use FileSaver.js which that can handle most of the corner cases/multiple browser support for save (or in this case, open) a file in javascript.

    0 讨论(0)
  • 2020-12-14 19:07

    As per the below link:-

    https://caniuse.com/#feat=download

    Safari 13 Beta 3 is released so you can check on the same, whether its working or not?

    You can download a blob got from a base64 by using a atob function.

    The atob function will decode a base64-encoded string into a new string with a character for each byte of the binary data.

    You can save blob locally via FileSaver.js .

    You can also check here that would be helpful:- How to open Blob URL on Chrome iOS

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