Mikee Mikee - 5 months ago 62
Javascript Question

Download data url file

I'm playing with the idea of making a completely javascript based zip/unzip utility that anyone can access from a browser. They can just drag their zip directly into the browser and it'll let them download all the files within. They can also create new zip files by dragging individual files in.

I know it'd be better to do it serverside, but this project is just for a bit of fun.

Dragging files into the browser should be easy enough if I take advantage of the various methods available. (gmail style)

Encoding/decoding should hopefully be fine. I've seen some as3 zip libraries so I'm sure I should be fine with that.

My issue is downloading the files at the end..

window.location = 'data:jpg/image;base64,/9j/4AAQSkZJR....'

this works fine in firefox but not in chrome.

I can embed the files as images just find in chrome using
<img src="data:jpg/image;ba.." />
, but the files wont necessarily be images. They could be any format.

Can anyone think of another solution or some kind of work around?



  • Try a <a href="data:...." target="_blank"> (Untested)

  • Use downloadify instead of data URLs (would work for IE as well)