Reading A Local File, Encoding To Base64, I Would Like To Give The User An Option To Save The Result To File
I have a webpage encoding a local file into Base64, and would like to give the user an option to save the result - now residing in a html element - without going back to the server
Solution 1:
You could do it like this:
var file = //your Base64 encoded filevar url = 'data:application/octet-stream;base64,' + file;
window.open(url);
You should adapt the code so the mime type matches the content you are serving (application/pdf...)
To pass a file name you will have to use a anchor tag like follows :
<ahref="data:application/octet-stream;base64,/*YOUR FILE DATA*/"download="your filename">
but this is not crossbrowser. See http://updates.html5rocks.com/2011/08/Downloading-resources-in-HTML5-a-download
Post a Comment for "Reading A Local File, Encoding To Base64, I Would Like To Give The User An Option To Save The Result To File"