I'm developing a client side music player and am looking for a way to save playlists complete with the mp3 data.
localStorage The 5mb limit for localStorage rules that option out. I'm wondering what other options there are.
DataURIs I've read about dataURIs e.g. Is there any way to specify a suggested filename when using data: URI? and Cross-browser Save As .txt but not suggesting a default filename and particularly lack of IE support are dealbreakers.
IndexedDB HTML5 indexedDB and persistence lifetime suggests that IndexedDB is not an option for persistent storage.
Are there options I am missing? I hope so!
Thanks, Andrew
I now have a solution which works in IE, Chrome and Firefox, inspired by this: Javascript set file in download
The IE10+ solution uses msSaveBlob and the code is:
if (navigator.msSaveBlob) {
var blob_object = new Blob([store_string], {type: mime_type});
return navigator.msSaveBlob(blob_object, filename);
}
For Chrome/Firefox it uses the download attribute:
else if ('download' in a) {
blob_object = new Blob ([store_string], {type: mime_type});
a.href = URL.createObjectURL(blob_object);
a.setAttribute("download", filename);
a.innerHTML = "downloading...";
d.body.appendChild(a);
setTimeout(function() {
a.click();
d.body.removeChild(a);
}, 66);
return true;
}
I haven't yet investigated Safari, Opera or any mobile browsers...
No - a cross-browser SaveAs solution is not possible.
Chrome, IE, & FF all support one (or multiple) ways to programmatically trigger the download (and saveAs dialog) of a file. Safari does not support this functionality.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With