Created
September 27, 2018 15:11
-
-
Save ArmandoAssuncao/6dbe9ad91f8b5380bb8438bd0fe1fee9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import JSZip from 'jszip'; | |
import JSZipUtils from 'jszip-utils'; | |
import saveAs from 'file-saver'; | |
function urlToPromise(url) { | |
return new Promise(function(resolve, reject) { | |
JSZipUtils.getBinaryContent(url, function (err, data) { | |
if(err) { | |
reject(err); | |
} else { | |
resolve(data); | |
} | |
}); | |
}); | |
} | |
function saveFilesToZip() { | |
const zip = new JSZip(); | |
const folder_name = 'folder_name' | |
zip.folder(folder_name); | |
const url = 'http://www.url_file.extension' | |
const pdf_name = 'pdf_name.extension' | |
zip.file(`${folder_name}/${pdf_name}.pdf`, urlToPromise(url), {binary:true}); | |
zip.generateAsync({type:"blob"}) | |
.then(function(content) { | |
zip_name = 'zip_name.zip' | |
saveAs(content, zip_name); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment