'Amazon S3 Create Object Error: POST requires exactly one file upload per request

I am trying to create an object via postman rest client with the following request. It gives the below-mentioned error. What could be the reason for this? Can anyone help me to fix this?

Request:

POST HTTP/1.1
Host: 1465549420742testconbkt2.s3-us-west-2.amazonaws.com
x-amz-date: Fri, 10 Jun 2016 09:03:47 GMT
Authorization: xxxxxx
Content-Type: multipart/form-data;boundary=----WebKitFormBoundaryE19zNvXGzXaLvS5C
Cache-Control: no-cache

----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="file"; filename="testFile.txt"
Content-Type: text/plain


----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="acl"

public-read-write
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="key"

testFile.txt
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="success_action_status"

200
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="AWSAccessKeyId"

AKIAJQJTU6FXS7TC2DTA
----WebKitFormBoundaryE19zNvXGzXaLvS5C

Response:

<Error>
    <Code>InvalidArgument</Code>
    <Message>POST requires exactly one file upload per request.</Message>
    <ArgumentName>file</ArgumentName>
    <ArgumentValue>0</ArgumentValue>
    <RequestId>B1EE3A8D9EA832AE</RequestId>
    <HostId>dqOG4gKXDXYKomDig1VD559Wc3XCLvPPB+uUiM6xKNiOVeMH+dvqDrAv47zy15qDIz/WvO+T3rQ=</HostId>
</Error>

Thanks in advance



Solution 1:[1]

You have an error in your boundary:

It need "--"(2 dash) more than the header so:

Content-Type: multipart/form-data;boundary=----WebKitFormBoundaryE19zNvXGzXaLvS5C

Should be:

Content-Type: multipart/form-data;boundary=------WebKitFormBoundaryE19zNvXGzXaLvS5C

Apparently for Post request

From:
HTTP POST with HttpWebRequest

Solution 2:[2]

The file or content must be the last field in the form. Any fields below it are ignored.

http://docs.aws.amazon.com/AmazonS3/latest/dev/HTTPPOSTForms.html

Yours is not last. It's followed by other form fields, and presumably this is confusing S3 into thinking you have more than one file. Granted, the "ignored" in the docs is not entirely consistent with my explanation, but that could be a side effect of uploading a small file, if that's what you're doing... fields that begin within about the first 20K of the upload may not always be ignored if they come after the file.

Solution 3:[3]

I believe your boundary values need to be prefixed with -- for each entry and the last boundary value needs to be suffixed with -- as follows (also as mentioned before, file needs to go last):

POST HTTP/1.1
Host: 1465549420742testconbkt2.s3-us-west-2.amazonaws.com
x-amz-date: Fri, 10 Jun 2016 09:03:47 GMT
Authorization: xxxxxx
Content-Type: multipart/form-data;boundary=----WebKitFormBoundaryE19zNvXGzXaLvS5C
Cache-Control: no-cache

------WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="acl"

public-read-write
------WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="key"

testFile.txt
------WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="success_action_status"

200
------WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="AWSAccessKeyId"

AKIAJQJTU6FXS7TC2DTA    
------WebKitFormBoundaryE19zNvXGzXaLvS5C

Content-Disposition: form-data; name="file"; filename="testFile.txt"
Content-Type: text/plain
------WebKitFormBoundaryE19zNvXGzXaLvS5C--

Solution 4:[4]

I was having the same error, the problem for me was that indeed the file was "empty".

I had the request saved for a long time, and maybe I missplaced the file in my computer, and the reference Postman had was broken (I haven't seen message in the console of Postman though)

enter image description here

Adding again the file solved it. No more "POST requires exactly one file upload per request." error message.

I am not sure how that would translate to the HTTP code request being used by all the answers here, and I don't think that copying the HTTP code here will help, since I believe POSTMAN strips the actual contents of the file, but to give more info, I have it like this:

----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="sample-mp4-file-small.mp4"
Content-Type: <Content-Type header here>

(data)
----WebKitFormBoundary7MA4YWxkTrZu0gW

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 Michael - sqlbot
Solution 3 Vamos
Solution 4 Cesc