Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS S3: should I use POST or PUT requests to upload a file?

I would like to know the pros and cons of using POST or PUT request to upload a file to Amazon Web Services S3.

I've already read some SO question like this one, but I would like to know the specific differences when using the AWS API.

I managed to use both, but hardly see the difference. I am using both PUT and POST via AJAX and the XMLHTTPRequest object, to upload directly from the browser with a node.js backend generating the signature.

The difference I noticed is that I can't restrict content-type and length server-side with PUT when I generate the signature, but this could be because I am just learning it now.

like image 762
Damien Monni Avatar asked Jun 03 '17 07:06

Damien Monni


People also ask

What is the difference between S3 PUT and POST?

POST: Takes in data, applies it to the resource identified by the given URI, here the rules you documented for the resource media type are followed. PUT: It will replace whatever is identified by the given URI with this data, and ignore whatever is in there already, if anything.

What is the best way for the application to upload the large files in S3?

When you upload large files to Amazon S3, it's a best practice to leverage multipart uploads. If you're using the AWS Command Line Interface (AWS CLI), then all high-level aws s3 commands automatically perform a multipart upload when the object is large. These high-level commands include aws s3 cp and aws s3 sync.

What is the recommended way to upload a single large file to an S3 bucket?

Instead of using the Amazon S3 console, try uploading the file using the AWS Command Line Interface (AWS CLI) or an AWS SDK. Note: If you use the Amazon S3 console, the maximum file size for uploads is 160 GB. To upload a file that is larger than 160 GB, use the AWS CLI, AWS SDK, or Amazon S3 REST API.


1 Answers

Apart from the differences you noticed, when using POST, the response you get contains The object key name. This is useful if you upload multiple objects in parallel, to identify which upload succeeded or not in the callback.

Also for access control, you can use POST and PUT differently (e.g Not allowing object modification, while only allowing creation)

like image 159
Ashan Avatar answered Sep 17 '22 23:09

Ashan