1

Pretty new user to Firebase here. I am trying to zip a .wav file from Firebase right now and I am currently stuck on using jszip in order to zip the files from the download URLs I pull from Firebase. The URLs look like this:

https://firebasestorage.googleapis.com/v0/b/instasample-d8eea.appspot.com/o/kick%2F1.wav?alt=media&token=91612541-83e5-4e82-ae1b-b56bc421e36b 

Every time I click the download button on my site, this function runs. I successfully get the download URL, and put it into the var urls.

But I get an error that I am not allowed access to this file and an invalid state error. This puzzles me because I am able to manually go to the link and right click -> save target as just fine.

Thank you so much for any suggestions, go easy on me I am new to jszip and Firebase. This is my code:

    function download(downloadType) {
      //alert(downloadType)
        var storageRef = firebase.storage().ref(downloadType + "/" + "1.wav"); //file name
        //todo: get 16 random file links, use for loop for thing below
        storageRef.getDownloadURL().then(function(url) {
          var downloadLink = url; //download link

          //////////////////////// do download stuff here ////////////////////////
          var zip = new JSZip();
          var count = 0;
          var zipFilename = "zipFilename.zip";
          var urls = [
            downloadLink
          ];

          urls.forEach(function(url){
            var filename = "filename";
            // loading a file and add it in a zip file
            JSZipUtils.getBinaryContent(url, function (err, data) {
               if(err) {
                  throw err; // or handle the error
               }
               zip.file(filename, data, {binary:true});
               count++;
               if (count == urls.length) {
                 var zipFile = zip.generate({type: "blob"});
                 saveAs(zipFile, zipFilename);
               }
            });
          });

Error message when I press download

AL.
  • 36,815
  • 10
  • 142
  • 281
Nick Garver
  • 527
  • 1
  • 5
  • 18
  • 1
    are you testing this from localhost? – mjr Oct 03 '16 at 16:53
  • 1
    @mjr yes I am. Would that affect anything? – Nick Garver Oct 03 '16 at 16:54
  • 2
    Not sure if it's the full problem, but you're hitting: http://stackoverflow.com/questions/37760695/firebase-storage-and-access-control-allow-origin – Mike McDonald Oct 03 '16 at 16:55
  • 1
    @MikeMcDonald thanks for the great suggestion, I just followed it and resolved the cross origin issue. that totally makes sense. Now I am getting a Uncaught Error: This method has been removed in JSZip 3.0, please check the upgrade guide. ;( looks like i will need to change up the var zipFile = zip.generate({type: "blob"}); line of code – Nick Garver Oct 03 '16 at 17:13

1 Answers1

1

thanks to @MikeMcDonald i fixed both of these errors with this post: Firebase Storage and Access-Control-Allow-Origin

I am now getting:

Uncaught Error: This method has been removed in JSZip 3.0, please check the upgrade guide.

Looks like I can finally move on. Thanks!

Community
  • 1
  • 1
Nick Garver
  • 527
  • 1
  • 5
  • 18