Downloading file from DataURL in JavaScript

前端 未结 2 777
孤街浪徒
孤街浪徒 2021-02-04 17:17

From this string we get from DataURL, what\'s the best way to download this as a file?

So far what I got was using a basic window.open(\"myDataURL\");, but

相关标签:
2条回答
  • 2021-02-04 17:40

    you can add a download attribute to the anchor element. sample:

    <a download="abcd.zip" href="data:application/stream;base64,MIIDhTCCAvKg........">download</a>
    
    0 讨论(0)
  • 2021-02-04 17:40

    Try this:

    data:application/msword;fileName=test.doc;base64,0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAACAAAANQAAAAAAAAAAEAAANwAAAAIAAAD+////AAAAADQAAABsAA/
    

    But this is just a guess from googling around and might be browser-dependent. The real answer to this is, you can't - See http://www.ietf.org/rfc/rfc2397 for reference, there's nothing in the specification to support a filename.

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