3

Below code is not working for me, it's giving timeout issue with while uploading the images to Amazon S3.

function resizeAndUploadToS3( imageData, imageHeader, bucket, key ) {
  return new Promise( ( resolve, reject ) => {
    sharp( imageData.data ).resize( 100, 100 ).toBuffer( function ( err, data ) {
      s3.putObject( {
        Bucket: bucket,
        Key: key,
        ACL: 'public-read',
        ContentType: imageHeader['content-type'],
        ContentLength: imageHeader['content-length'],
        Body: data
      }, ( err, status ) => {
        console.log( 'err:::', err );
        console.log( 'status:::', status );
        resolve( status );
      } );
    } );
  } );
}

I tried to save resized image into the local file using below code and its working fine

sharp( imageData.data ).resize( 100, 100 ).toFile('test.jpg');

Also, I tried to upload the images without resizing to S3 and it works fine. What could be the issue?

Mohd Shahid
  • 1,538
  • 2
  • 33
  • 66

1 Answers1

1

I fixed it by removing given lines from above code.

ContentType: imageHeader['content-type'],
ContentLength: imageHeader['content-length'],

I think value of content-type and content-length was wrong in my case.

Mohd Shahid
  • 1,538
  • 2
  • 33
  • 66
  • 1
    I think that only `content-length` was the culprit, in my case I removed it and it worked. – Karl.S Dec 22 '20 at 04:12