Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

amazon-s3

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

like image 774
Shakila Sasikaran Avatar asked Oct 19 '22 07:10

Shakila Sasikaran


2 Answers

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

like image 163
Destrif Avatar answered Nov 03 '22 00:11

Destrif


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.

like image 30
Michael - sqlbot Avatar answered Nov 02 '22 23:11

Michael - sqlbot