Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have unzipped the zip files to buffer.Now I need to upload those unzipped files from buffer to S3 bucket using node js.Kindly help me to proceed.

What I have tried:

I can upload the files from my local drive to S3.But I need to upload the files which is stored in buffer.The below code says - downloading zip file from s3 and extracting to buffer.Now I need to upload those extracted files to S3 Bucket
var data = [], dataLen = 0;
s3.getObject(params)

    .on('httpData', function (chunk) {

    data.push(chunk);
    dataLen += chunk.length;

   // file.write(chunk);

}).

on('httpDone', function (err) {
    if (err) { 
        console.log(err);
    }

    var buf = new Buffer(dataLen);

    for (var i = 0, len = data.length, pos = 0; i < len; i++) {
        data[i].copy(buf, pos);
        pos += data[i].length;
    }

     var zip = new AdmZip(buf);

    var zipEntries = zip.getEntries();
    console.log(zipEntries.length)

    for (var i = 0; i < zipEntries.length; i++)
        console.log(zip.readAsText(zipEntries[i]));
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900