Mohd Shahid
Mohd Shahid

Reputation: 1606

Nodejs Sharp Image Resize and Upload to S3 gives timeout

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?

Upvotes: 3

Views: 3731

Answers (1)

Mohd Shahid
Mohd Shahid

Reputation: 1606

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.

Upvotes: 1

Related Questions