19

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.

Damien Monni
  • 1,418
  • 3
  • 15
  • 25
  • 1
    in terms of API design guidelines, A POST request is used to send data to the server, for example, customer information, file upload, etc. using HTML forms. And PUT request is used to replaces all current representations of the target resource with the uploaded content. – Pranav Patel Jun 03 '17 at 08:08
  • Yes but my question is more AWS specific. I want the pros and cons of using both with AWS S3 – Damien Monni Jun 03 '17 at 08:12
  • *The difference I noticed is that I can't restrict content-type and length server-side with PUT when I generate the signature.* Question: Are you using Signature Version 2 or 4? A V4 signature can be identified by seeing `Authorization: AWS4-HMAC-SHA256 ...` if using headers or `X-Amz-Algorithm=AWS4-HMAC-SHA256` if using the query string. – Michael - sqlbot Jun 03 '17 at 11:46
  • I am using signature V4 – Damien Monni Jun 03 '17 at 12:15
  • refer: https://bhupenderhbti.blogspot.com/2017/10/what-is-idempotence-in-rest-api.html – Balakrishnan May 29 '19 at 02:52

1 Answers1

1

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)

Ashan
  • 18,898
  • 4
  • 47
  • 67