Most questions regarding NodeJS, S3 and Zips are the opposite of what I would like to do. Upload a zip, and extract the files onto S3.
I have a quick app running on an Amazon EC2 instance, with Node.JS that accepts a file upload via a POST request. The aim is to upload a zip file full of images, extract them, and place each individual image on Amazon S3.
I am using express.js to accept the posted file, and I have been playing with AdmZip to read the uploaded zip file. With AdmZip, I can extract the zip file to the servers disk, then loop over each extracted image in a temporary directory and then send that to Amazon S3, but this seems very inefficient. I've read quite a bit about streaming files from S3 to Node and zipping it on the fly. I guess what I want to know is if this is possible in reverse.
I Don't think you'll be able to extract the file "on" S3. You'll have to save the zip in /temp, extract and upload the indiviual files to s3.
Try some thing like this:
app.post('/upload', function (req, res, next) {
myZip = req.files.myZipfile
var zip = new require('node-zip')(myZip, {base64: false, checkCRC32: true});
knox = require('knox');
s3 = knox.createClient({"key": "", "secret": "", "bucket": ""})
// You might need to try something like async here to throttle the putFile command
for (var i = zip.files.length - 1; i >= 0; i--) {
s3.putFile(zip.files[i], path.basename(zip.files[i]), function(err, res) {
});
};
});