I try to find example where I can send a zip (like via postman) and get this zip in my handler and unzip it so specified folder I didn't find much examples for zipping using express I want to unzip it in path web/app
I try something like the following which doesn't works for me , the zip file is not unzipped in the specified folder, any idea what im doing wrong ?
https://nodejs.org/api/zlib.html#zlib_zlib
var zlib = require('zlib');
var fs = require('fs');
const dir = path.join(__dirname, 'web/app/');
if (req.file.mimetype === 'application/zip') {
var unzip = zlib.createUnzip();
var read = fs.createReadStream(req.file);
var write = fs.createWriteStream(dir);
//Transform stream which is unzipping the zipped file
read.pipe(unzip).pipe(write);
console.log("unZipped Successfully");
}
Any working example will be very helpful, or reference where can I've problem...
while debug I see the that this is when the code failed
var read = fs.createReadStream(req.file);
any idea why?
I've also tried with
var read = fs.createReadStream(req.file.body);
the issue that I dont see the error, reason etc.
when I change it to
var read = fs.createReadStream(req.file.buffer);
the program doesnt exit and i was able to run it until the logger console.log("unZipped Successfully"); but nothing happen...
if there any example with https://www.npmjs.com/package/yauzl yauzl and multer in my context it will be great
from Extract zip into folder node via express
No comments:
Post a Comment