admin管理员组

文章数量:1289834

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.

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.

Share Improve this question asked Jun 3, 2017 at 7:53 Damien MonniDamien Monni 1,5483 gold badges16 silver badges28 bronze badges 5
  • 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 Commented Jun 3, 2017 at 8:08
  • Yes but my question is more AWS specific. I want the pros and cons of using both with AWS S3 – Damien Monni Commented Jun 3, 2017 at 8: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 Commented Jun 3, 2017 at 11:46
  • I am using signature V4 – Damien Monni Commented Jun 3, 2017 at 12:15
  • refer: bhupenderhbti.blogspot./2017/10/… – Balakrishnan Commented May 29, 2019 at 2:52
Add a ment  | 

1 Answer 1

Reset to default 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)

本文标签: javascriptAWS S3 should I use POST or PUT requests to upload a fileStack Overflow