Wednesday, 19 April 2017

Extract images from zip(tar.gz) file and upload to S3,but the bytes transferred is larger than actual file size.So I cannot open the image file

I am extracting the image files and xml file from tar.gzip and upload the files to s3 upload from the chunks.

After uploaded the file to S3 bucket,the image file bytes transferred size is larger than actual size.The original size is 280 kb.But the transferred file size is 510 kb.

Because of this size,am getting an error, when I open the Image file.Not only image files ,same problem is there in xml file also.

When debugging the code => while extracting data chunk showed binary data,but while assign the chunks to file name it shows the file data "undefined�PNG". Please help me!!!

This is my code.

function extractData() {

var zipFile = Student.tar.gz;

params = { Bucket: bucketName, Key: zipFile };

s3.getObject(params).createReadStream()
    .pipe(zlib.createGunzip())
    .pipe(extract);

 var files = {};

 extract.on('entry', function (header, stream, cb) {
    stream.on('data', function (chunk) {

        if (Object.keys(header.name) !== undefined) {

            files[header.name] += chunk;
        } else {

            files[header.name] = chunk;
        }
    });

    stream.on('end', function () {
        cb();
    });

    stream.resume();
});

extract.on('finish', function () {

    Object.keys(files).forEach(function (filename)  
       {
       UploadFilestoS3(filename, files[filename]);
        }
    });
  });
}

 function UploadFilestoS3(fname, data) {

    var uploader = s3.upload({
    Bucket: bucketName,
    Key: fname, 
    Body: data
  }, 
}



via vishnu

No comments:

Post a Comment