最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

filewriter - Downloading file from DataURL in JavaScript - Stack Overflow

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论