1

I'm using Amazon S3 as photo storage and I'm constantly getting this error:

RequestTimeout: Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.

Here's the code:

function(source, name, callback) {
  var awsUtils = this;
  fs.stat(source, function(err, file_info) {
    console.log(file_info);
    var bodyStream = fs.createReadStream(source);
    var params = {
        Key           : name,
        ContentLength : file_info.size,
        Body          : bodyStream
    };
    awsUtils.s3bucket.putObject(params, function (err, data) {
      if(err) {
        console.error('AWSDriverUtils-unable to upload: ' + err);
        callback(false);
      } else {
        console.log('AWSDriverUtils-upload success:', data);
        callback(true);
      }
    });
  });
}

The upload image file is small, about 44.0 KB only. While researching, I have found someone saying:

Amazon S3 will send that error response after 20 seconds of inactivity. The error indicates that Amazon S3 was attempting to read the request body, but no new data arrived over a period of 20 seconds.

What should I do to fix this, maybe a flush() function?
I have also tried to comment out ContentLength in params.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
Vinh.TV
  • 299
  • 3
  • 17
  • I am having a problem passing an image file to Node JS so I could upload it to `AWS S3`. Can you please share your code so it'll help me solve my problem. I have also posted my question here. http://stackoverflow.com/questions/38621876/upload-image-from-jquery-to-node-js/38622712 – Illep Jul 28 '16 at 08:12
  • Hi, I receive an image from mobile apps which has decoded image file into base64 string, therefore the receiving step in server is very straightforward. Like this: var decodedImage = new Buffer(req.body.base64Image, 'base64'); – Vinh.TV Jul 29 '16 at 02:12
  • Can you show me how you pass it from your front end (HTML/JQuery code) ? – Illep Jul 29 '16 at 03:50

0 Answers0