Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERR_CONNECTION_RESET Error when uploading large files to Amazon S3

I am following this tutorial :

https://devcenter.heroku.com/articles/s3-upload-node

to upload files to Amazon s3 using NodeJS and Jquery. It works fine for small images and files. However it gives a XHR Connection RESET Error.

My CORS Configuration looks exactly like this:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
   <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

Am I missing something?

like image 207
Devesh Kumar Avatar asked Apr 24 '14 02:04

Devesh Kumar


1 Answers

if you followed the instructions given in heroku documentation, you'll see a line

  const s3Params = {
Bucket: S3_BUCKET,
Key: fileName,
Expires: 60,
ContentType: fileType,
ACL: 'public-read'};

As you can see in this aws documentaion ,the Expires metadata means that the number of seconds to expire the pre-signed URL operation. Here it is given as 60 which equals 1 minute. Uploading large files within the span of 60 sec. is not possible.

FIX:try removing the expire metadata from s3Params or increase the value. By default a presigned url expires in 15 minutes.

Now your code will look like this:

  const s3Params = {
Bucket: S3_BUCKET,
Key: fileName,
ContentType: fileType,
ACL: 'public-read'};
like image 126
Rishan KP Avatar answered Sep 22 '22 14:09

Rishan KP