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.
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.
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With