filewriter - Downloading file from DataURL in JavaScript - Stack Overflow

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

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 I'm not able to change the file name in this way.

window.open('data:application/msword;base64,0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAA
             PgADAP7/CQAGAAAAAAAAAAAAAAACAAAANQAAAAAAA
             AAAEAAANwAAAAIAAAD+////AAAAADQAAABsAA/',
             '_blank','height=300,width=400');

I was wondering if there's any way to handle this data properly.

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 I'm not able to change the file name in this way.

window.open('data:application/msword;base64,0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAA
             PgADAP7/CQAGAAAAAAAAAAAAAAACAAAANQAAAAAAA
             AAAEAAANwAAAAIAAAD+////AAAAADQAAABsAA/',
             '_blank','height=300,width=400');

I was wondering if there's any way to handle this data properly.

Share Improve this question edited Jan 9, 2012 at 17:35 Ry- 225k56 gold badges492 silver badges498 bronze badges asked Jan 9, 2012 at 17:33 eBergamoeBergamo 1011 gold badge3 silver badges6 bronze badges 3
  • See stackoverflow./a/6465780/27862 – user123444555621 Commented Jan 9, 2012 at 17:46
  • I've seen this question before, the file name bees "rVPjLUq1.part", just as if I were using the example I posted above. – eBergamo Commented Jan 9, 2012 at 18:02
  • As Wladimir Palant writes, the issue has been discussed on the W3C mailing list, but "this doesn't seem to have made it into any specification so far, let alone browser implementations." I'm afraid there hasn't been any progress in that matter. – user123444555621 Commented Jan 10, 2012 at 10:51
Add a ment  | 

2 Answers 2

Reset to default 3

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

<a download="abcd.zip" href="data:application/stream;base64,MIIDhTCCAvKg........">download</a>

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/rfc/rfc2397 for reference, there's nothing in the specification to support a filename.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742356472a4428538.html

相关推荐

  • filewriter - Downloading file from DataURL in JavaScript - Stack Overflow

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

    2天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信