UWP Saving zip file to disk

Viewed 407

I have a UWP app written in HTML/Javascript and im having trouble saving a zip file made from JSZip. Specifically writing it to disk is where I am hung up at.

I see in the Microsoft docs that there is WriteBufferAsync, WriteBytesAsync, WriteLinesAsync, and WriteTextAsync. Im not sure which one I need for this. Also JSZip can generate different types like base64, binarystring, uint8array, arraybuffer, and blob. Im just not sure what combination I need to write this zip file to the users disk.

Below is my code:

savePNGButton.addEventListener('click', function (e) {
  var zip = new JSZip();
  if (WatermarkText === ""){
    ZipFolder = zip.folder("ImageFolder");
  } else {
    ZipFolder = zip.folder(WatermarkText);
  }
  $(".WatermarkPhoto").each(function(index) {
   imgsrc = this.src;
   var DataURL = imgsrc.replace('data:image/png;base64,', '');
   ZipFolder.file(WatermarkText + index + ".png", DataURL, { base64: true });

  });
  zip.generateAsync({ type:"blob"})
      .then(function (content) {
          console.log(content);
          var savePicker = new Windows.Storage.Pickers.FileSavePicker();
          savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
          savePicker.fileTypeChoices.insert("ZIP archive", [".zip"]);
          savePicker.suggestedFileName = WatermarkText+".zip";
          savePicker.pickSaveFileAsync().then(function (file) {
              if (file) {
                  Windows.Storage.CachedFileManager.deferUpdates(file);
                  Windows.Storage.FileIO.writeTextAsync(file, content).done(function () {
                      Windows.Storage.CachedFileManager.completeUpdatesAsync(file).done(function (updateStatus) {
                          if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
                              console.log("File " + file.name + " was saved.");
                          } else {
                              console.log("File " + file.name + " couldn't be saved.");
                          }
                      });
                  });
              } else {
                  console.log("Operation cancelled.");
              }
          });
      });
});
1 Answers
Related