Error: The body of your POST request is not well-formed multipart/form-data.
See original GitHub issueI am using angular file upload and getting the error message: The body of your POST request is not well-formed multipart/form-data.
The purpose is to upload a file to S3 using this method.
http://aws.amazon.com/articles/1434
Here is the code:
$scope.onFileSelect = function($files) {
for (var i = 0; i < $files.length; i++) {
var $file = $files[i];
AWS.get({partId: $stateParams.id, bucket: ""}, function(response){
var formData = {
key: "/OEM/PARTS/" + $stateParams.id + "/" + $file.name,
AWSAccessKeyId: "AKIAJDWFD4T7GQZNZBNQ",
acl: 'private',
success_action_redirect: "#",
policy: response.policy,
signature: response.signature,
'Content-Type': $file.type
};
$http.uploadFile({
method: 'POST',
url: 'https://tennex.s3.amazonaws.com/',
headers: {'Content-Type': 'multipart/form-data',
//this clears the default Authorization code.
Authorization: ""},
data: formData,
file: $file
}).progress(function(evt) {
console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total));
}).then(function(data, status, headers, config) {
// file is uploaded successfully
console.log(data);
});
}, function(){
alert("failed to download policy file");
});
}
};
Here is the request and response http headers:
Request URL:https://tennex.s3.amazonaws.com/ Request Method:POST Status Code:400 Bad Request Request Headersview source Accept:/ Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en;q=0.8 Authorization: Cache-Control:no-cache Connection:keep-alive Content-Length:319662 Content-Type:multipart/form-data Host:tennex.s3.amazonaws.com Origin:http://localhost:63342 Pragma:no-cache Referer:http://localhost:63342/app/views/OEM/index.html User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Request Payload ------WebKitFormBoundary85lPiaZFfRGERy4T Content-Disposition: form-data; name=“key”
/OEM/PARTS/30/Tesla 2013 05 17.pdf ------WebKitFormBoundary85lPiaZFfRGERy4T Content-Disposition: form-data; name=“AWSAccessKeyId”
AKIAJDWFD4T7GQZNZBNQ ------WebKitFormBoundary85lPiaZFfRGERy4T Content-Disposition: form-data; name=“acl”
private ------WebKitFormBoundary85lPiaZFfRGERy4T Content-Disposition: form-data; name=“success_action_redirect”
------WebKitFormBoundary85lPiaZFfRGERy4T Content-Disposition: form-data; name=“policy”
eydleHBpcmF0aW9uJzogJzIwMTMtMTAtMjJUMjI6NTM6NTZaJywgJ2NvbmRpdGlvbnMnOiBbIHsnYnVja2V0JzogJ3Rlbm5leCd9LCBbJ3N0YXJ0cy13aXRoJywgJyRrZXknLCAnT0VNL1BBUlRTLzMwLycgXSwgeydhY2wnOiAncHJpdmF0ZSd9LCB7J3N1Y2Nlc3NfYWN0aW9uX3JlZGlyZWN0JzogJyMnLCB9IFsnc3RhcnRzLXdpdGgnLCAnJENvbnRlbnQtVHlwZScsICcnXV19IA== ------WebKitFormBoundary85lPiaZFfRGERy4T Content-Disposition: form-data; name=“signature”
a55375e793cf0debb8f1077c760b3aa00cff43dd ------WebKitFormBoundary85lPiaZFfRGERy4T Content-Disposition: form-data; name=“Content-Type”
application/pdf ------WebKitFormBoundary85lPiaZFfRGERy4T Content-Disposition: form-data; name=“file”; filename=“Tesla 2013 05 17.pdf” Content-Type: application/pdf
------WebKitFormBoundary85lPiaZFfRGERy4T– Response Headersview source Access-Control-Allow-Credentials:true Access-Control-Allow-Methods:GET, PUT, POST Access-Control-Allow-Origin:http://localhost:63342 Access-Control-Max-Age:3000 Connection:close Content-Type:application/xml Date:Tue, 22 Oct 2013 22:44:05 GMT Server:AmazonS3 Transfer-Encoding:chunked Vary:Origin, Access-Control-Request-Headers, Access-Control-Request-Method x-amz-id-2:wkp3NyL+kJBebuNUN9RYEvsDYLGZEKHXm7rqB7VuxVmPDEAFnXX0SZuo8Dy88hBG x-amz-request-id:80A54AF54999B9EB
Issue Analytics
- State:
- Created 10 years ago
- Reactions:1
- Comments:50 (21 by maintainers)
Top GitHub Comments
Remove ‘Content-Type’: ‘multipart/form-data’, from headers and see if it works. Otherwise send an upload request using regular form with action like the amazon template and catch the content of the requests. Then we can compare what is the difference and what is missing in the data.
Wow 8 year old thread, but still want to leave my solution for folks who run across this thread like I did. I was getting the same error from AWS S3:
Ended up fixing this by adding 5000 to the
Content-Length
header, which had already been set to the video size in bytes I was uploading to AWS S3 with NodeJS Axios. I assume my specifiedContent-Length
value was shorter than the actual request length, and AWS didn’t like that. Very useful error they spit at me… Also, note that I used...fd.getHeaders()
, this is important to keep for setting other headers.Here’s the final working code I used:
Very frustrating to debug, and never found any help through AWS docs. I sent them feedback to improve the docs or the API error message. Hope this is helpful to someone down the road!