Aws-sdk-js: aws s3 file upload request timeout

Created on 18 Apr 2018  路  3Comments  路  Source: aws/aws-sdk-js

`var fileStream = fs.createReadStream(file.file[0].path); var fileName = randomInteger+'_'+file.file[0].originalFilename; fileStream.on('error', function (err) { if (err) { console.log(err); reject(err); } }); fileStream.on('open', function () { var s3 = new AWS.S3(); s3.putObject({ Bucket: bucketName, Key: fileName, Body: fileStream, }, function (err, data) { if (err) { console.log(err); reject(err); }else{ var uploadUrl = "https://s3-eu-west-1.amazonaws.com/" + bucketName+ "/" + fileName; resolve(uploadUrl); } }); });

I tried to upload files to s3 bucket but it throws request timeout error error was threw in the first time of upload if i upload it 2nd 3rd time upload work without any errors

guidance

Most helpful comment

Hi @jaggu07
This probably because the S3 client is requesting a wrong endpoint region. After the first fail try(us-east-1 as default), the S3 client will update its endpoint with correct region so that the following retries are successful. You can try setting the bucket region in S3 constructor. If the bucket is in eu-west-1, you can construct like this: var s3 = new AWS.S3({region: 'eu-west-1'})

All 3 comments

Hi @jaggu07
This probably because the S3 client is requesting a wrong endpoint region. After the first fail try(us-east-1 as default), the S3 client will update its endpoint with correct region so that the following retries are successful. You can try setting the bucket region in S3 constructor. If the bucket is in eu-west-1, you can construct like this: var s3 = new AWS.S3({region: 'eu-west-1'})

Hi @AllanFly120
Thanks for your response... It worked for me

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

Was this page helpful?
0 / 5 - 0 ratings