Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading file from DataURL in JavaScript

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.

like image 301
eBergamo Avatar asked Jan 09 '12 17:01

eBergamo


1 Answers

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

<a download="abcd.zip" href="data:application/stream;base64,MIIDhTCCAvKg........">download</a>
like image 54
cuixiping Avatar answered Oct 02 '22 12:10

cuixiping