Monday, 17 April 2017

How to upload folder to s3 bucket using node js and how to specify the key name in s3 put object

Actually am unzipping the folders to buffer from s3 bucket.Then upload the folders from buffer to another s3 bucket.Kindly help me how to provide the params for s3 putobject to upload a folder.

This is my code.

var folderName = '';

function UnzipAndUpload() {
async.waterfall([
    function download(next) {
        s3.getObject(params, function (err, data) {
            next(err, data);
        });
    },
    function gunzip(response, next) {
        var buffer = new Buffer(response.Body);
        zlib.gunzip(buffer, function (err, decoded) {

            folderName = decoded.toString(); //Folders

            next(err, decoded && decoded.toString());

        });
    },
    function Upload(data, next) {
        UploadDataToS3(data, folderName);
                  // context.done();
    }
 ], function (err) {
    if (err) throw err;
 });
}

function UploadFilestoS3(data, folderName ) {

var extractedData = data;
s3.putObject({
    Bucket: bucketName,
    Key: "",              //What key name has to give for folders
    Body: extractedData,
  }, function (err) {
    console.log('uploaded file: ');
  });
}



via vishnu

No comments:

Post a Comment