rndme / download

file downloading using client-side javascript
MIT License
2.28k stars 417 forks source link

Chrome breaks if base64 url is bigger than 2MB #26

Closed albertogasparin closed 8 years ago

albertogasparin commented 8 years ago

This is quite an old bug but it looks like it has not been resolved yet. Basically when I try to use your plugin to download a base64 that is bigger than several MB (from a canvas), I get "network error" instead of the proper file. Probably you should switch to Blob if the base64 string is too long.

rndme commented 8 years ago

that's a neat idea. as download.js evolved, that was never considered because Blob support was shaky for a long time, and people's expectations about file size had been modest. It never converted a format unless it had to because of lack-of-support. I could easily close this out and say "not my problem", as it is a limit of dataURLs and/or browsers, but that won't help anyone. Indeed, it SHOULD be possible to convert long dataURLs into window.URLs and download them that way. I think the pieces are even there now (ex d2b()). thanks for the idea, and watch this space; i will try ti out and if workable, fold it into the next release. thanks again!

rndme commented 8 years ago

aside: you might want to use HTMLCanvasElement.prototype.toBlob instead of HTMLCanvasElement.prototype.toDataURL to save the user-land conversion overhead, it works in FF+Ch now...

albertogasparin commented 8 years ago

Yes, I know, but I will need a polyfill for Safari and IE. So having one plugin that does the job regardless the format is nicer. You are right, your lib already has all the bits and pieces. I did a quick test and by converting base64 strings longer than 2MB to Blob does the job.

Maybe you can also evaluate the opportunity to make Blob the default way. It has great browser support nowadays (IE10+)

rndme commented 8 years ago

i forgot to mention this was fixed: https://github.com/rndme/download/commit/8dfadcddb0f9091c8a7f2983a392be168613154b

thanks for the idea!