1

I need to save a large set of client-side generated data (binary) to the client system. I looked at creating a Data URI, but the datasize is large (an app-generated image PDF files of 100+ pages). Is there some other way to do this other than a Data URI?

Thanks!

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • By "saving" you mean starting the download? – Robert Feb 21 '15 at 15:04
  • That's not quite what I'm after; the application creates a huge file, but transfers it in 64K chunks of data; I need to go from that the incoming stream of data chunks to a downloaded file. It looks like the answer below will do what I need ... thanks! – Nathan Verrilli Feb 22 '15 at 20:11

1 Answers1

3

If you want to start a download this is the way to go:

  1. If you have more than one file to save: Pack it into a zip file. I wrote a dart based zip library (available at https://github.com/roberthartung/zip.dart). They key point is to use the zip file format for archiving data and not for compression (because this is really slow).

  2. If you have only one file (zip or any other format) you can load it into a blob and let the user download the blob like this:

Code

Blob blob = new Blob(...);
AnchorElement a = new AnchorElement();
a.style.display = 'none';
document.body.append(a);
String url = Url.createObjectUrlFromBlob(blob);
a.href = url;
a.download = "file.name";
a.click();
Url.revokeObjectUrl(url);

For chrome only there is the deprecated FileSystem API, which you could use to save persistent data, but I guess you want a download.

Robert
  • 5,484
  • 1
  • 22
  • 35
  • Yes -- that's exactly what I was after. II only have one file and it's already compressed but the 'createObjectUrlFromBlob' looks like exactly what I was after! Thanks! – Nathan Verrilli Feb 22 '15 at 20:13