ERR_CONNECTION_RESET when PUTting to S3

I run files on S3 through ajax requests and get errors ERR_CONNECTION_RESET about 50% of the time.

I know that the requests are signed correctly - any ideas that might be causing this? Again, this is an unsustainable problem that I see from several places and cars.

Here is the corresponding coffeescript code that I use to expose my files to S3. This comes from Mika Roberson and Rock Kruhl, working at http://micahroberson.com/upload-files-directly-to-s3-w-backbone-on-heroku/ and http://codeartists.com/post/36892733572/ how-to-directly-upload-files-to-amazon-s3-from-your .

createCORSRequest: (method, url) -> xhr = new XMLHttpRequest() if xhr.withCredentials? xhr.open method, url, true else if typeof XDomainRequest != "undefined" xhr = new XDomainRequest() xhr.open method, url else xhr = null xhr uploadToS3: (file, signature) -> this_s3upload = this this_s3upload.signature = signature url = signature.signed_request xhr = @createCORSRequest 'PUT', decodeURIComponent(signature.signed_request) if !xhr @onError 'CORS not supported' else xhr.onload = () -> if xhr.status == 200 this_s3upload.onProgress 100, 'Upload completed.' this_s3upload.onFinishS3Put file, this_s3upload.signature else this_s3upload.onError file, 'Upload error: ' + xhr.status xhr.onerror = () -> this_s3upload.onError file, 'XHR error.', this_s3upload.signature xhr.upload.onprogress = (e) -> if e.lengthComputable percentLoaded = Math.round (e.loaded / e.total) * 100 if percentLoaded == 100 message = "Finalizing" else message = "Uploading" this_s3upload.onProgress xhr, file, percentLoaded, message, this_s3upload.signature xhr.onabort = -> this_s3upload.onAbort file, "XHR cancelled by user.", this_s3upload.signature xhr.setRequestHeader 'Content-Type', file.type xhr.setRequestHeader 'x-amz-acl', 'public-read' xhr.send file 

Update

I get very attentive support from Amazon on this. At their suggestion, I created an EC2 Windows instance, loaded the Chrome browser onto it, and tried to upload 5 files 10 times with my code. Once I did not see a mistake. Sometimes I saw some SignatureDoesNotMatch errors, but not one ERR_CONNECTION_RESET error. I still see ERR_CONNECTION_RESET errors, although in every EC2 client / network I use I use.

Refresh . There is no solution. I switched from using a self-calibrated signature algorithm to one provided by boto. However, it does not affect the ERR_CONNECTION_RESET problem.

+7
ajax amazon-s3
source share
3 answers

I finally gave up work. Instead, I use Fine Uploader to provide this functionality.

+1
source share

I ran into this problem when loading large files (long requests) with pre-signed URLs, following Heroku's example (node ​​aws sdk):

 app.get('/sign-s3', (req, res) => { const s3 = new aws.S3(); const fileName = req.query['file-name']; const fileType = req.query['file-type']; const s3Params = { Bucket: S3_BUCKET, Key: fileName, Expires: 60, ContentType: fileType, ACL: 'public-read' }; s3.getSignedUrl('putObject', s3Params, (err, data) => { if(err){ console.log(err); return res.end(); } const returnData = { signedRequest: data, url: `https://${S3_BUCKET}.s3.amazonaws.com/${fileName}` }; res.write(JSON.stringify(returnData)); res.end(); }); }); 

The Expire option makes the signed URL valid for 60 seconds.

I realized that the request crashes when the signed URL expires in the middle of the download (even if it was valid at boot).

It does not fall exactly after 60 seconds, although randomly between 60 and 120 seconds. In most cases, the client registers ERR_CONNECTION_RESET, and in other cases it registers 403 FORBIDDEN.

After scrolling to 3600, I had no more problems.

I suspect that the problem did not happen on EC2 because they have very fast download speeds.

+1
source share

I believe this problem has no solution.

Try a POST request: https://aws.amazon.com/articles/1434

 <form action="https://s3-bucket.s3.amazonaws.com/" method="post" enctype="multipart/form-data"> <input type="hidden" name="key" value="uploads/${filename}"> <input type="hidden" name="AWSAccessKeyId" value="YOUR_AWS_ACCESS_KEY"> <input type="hidden" name="acl" value="private"> <input type="hidden" name="success_action_redirect" value="http://localhost/"> <input type="hidden" name="policy" value="YOUR_POLICY_DOCUMENT_BASE64_ENCODED"> <input type="hidden" name="signature" value="YOUR_CALCULATED_SIGNATURE"> <input type="hidden" name="Content-Type" value="image/jpeg"> <!-- Include any additional input fields here --> File to upload to S3: <input name="file" type="file"> <br> <input type="submit" value="Upload File to S3"> </form> 

Use FormData to add fields if you prefer to send AJAX

To sign the request in nodejs: Amazon S3 POST api and sign the policy with NodeJS

0
source share

All Articles