I have an ionic app in which I need to create zip of some files on the device and send them to node server.
I am trying to use JSZip [http://stuk.github.io/jszip/] to create a zip of the files on the device. I have complete path of each of the files which is send to the function in filesList array.
In the service
// complete path of all the files that need to be zipped is in filesList array
// Eg., file:///var/mobile/Containers/Data/Application/BACCA40A-56C4-4BE5-8C5D-1576960BD14B/Library/NoCloud/1473447800255.zip
var zipFiles = function(filesList) {
var uniqueFilename = Date.now();
var zip = new JSZip();
// create a zip with a unique name
var zipFolder = zip.folder(uniqueFilename);
//add files to the zip
filesList.forEach(function(file) {
zipFolder.file(file);
})
return zipFolder;
}
In the controller
myAPI.zipFiles(docList)
.then(function(result) {
console.log('Zip created '+JSON.stringify(result));
.catch(function(error) {
console.log('Error while creating zip '+error);
});
I would like to create a zip in memory (don’t need to save it on the device) and send it to node.
The code above is resulting in an empty zip even though filesList array has 5 files and the path to those files is also valid.
Can someone please help me in getting this correct or is there an alternate library that I should be using.