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);
}
});
});