7

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?

Devesh Kumar
  • 1,009
  • 1
  • 17
  • 29
  • Looks like multipart upload issue. Don't know much about node.js but this might help: http://stackoverflow.com/questions/16534892/multipart-file-uploads-using-nodejs – Rakesh Bollampally Apr 24 '14 at 12:33

1 Answers1

2

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'};
Rishan KP
  • 21
  • 3