Saturday, 15 April 2017

How to upload binary data to s3 using node js using s3 key attribute

I need to download and extracted files from s3 bucket and upload to another bucket.The files are downloaded properly and the result is returning as binary data using s3.getObject.

I need to pass the binary data to upload the files to s3.

But I dont know what name has to give for "Key" params in s3.putOBject when we push the binary data to s3.putObject. Kindly help me.

This is my code

s3.getObject(params, function(err, data,callback) {
if (err) {
    console.log(err);
    callback(err);
} 
else {
    zlib.gunzip(data.Body, function (err, result) {
        if (err) {
            console.log(err);
        } else {
            var extractedData = result;
            s3.putObject({
            Bucket: "bucketName",
            Key: "filename",
            Body: extractedData,
            ContentType: 'content-type'
            }, function (err) {
                 console.log('uploaded file: ' + err);
            });
        }
    });
  }
});



via vishnu

No comments:

Post a Comment