Amazon S3 Getting 501 Error on PUT
In testing a new app one tester always has his uploads to S3 fail. We're sending a PUT request of a ~1.2mb file to S3 and setting it's ACL perms. For him, he always gets a 501 - Not Implemented error.
Here are his headers on the request:
"Accep开发者_运维百科t-Encoding" = gzip;
Authorization = "AWS ###:###";
"Content-Encoding" = gzip;
"Content-Length" = 1420267;
"Content-Type" = "application/octet-stream";
Date = "Thu, 6 Oct 2011 02:59:47 +0000";
"User-Agent" = "MyApp 1.0 (iPhone; iPhone OS 4.3.1; en_US)";
"x-amz-acl" = "public-read-write";
Here are the response headers:
Connection = close;
"Content-Length" = 321;
"Content-Type" = "application/xml";
Date = "Thu, 06 Oct 2011 03:00:14 GMT";
Server = AmazonS3;
Any thoughts are welcome!
Response comes back with status code 501 and string - "A header you provided implies functionality that is not implemented"
501 response code from Amazon may be sent if no Content-Length is supplied.
Since you are saying that you do, I suggest running the request through a proxy ( Charles for Mac or Fiddler for Windows) and making sure that the request that's being sent actually includes the Content-Length header
The response body contains XML that lists the header it's not happy with, like this:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>NotImplemented</Code>
<Message>A header you provided implies functionality that is not implemented</Message>
<Header>If-Modified-Since</Header>
</Error>
I set the cache policy on my NSURLRequest to NSURLRequestReloadIgnoringCacheData and it stopped adding the unwanted If-Modified-Since header:
mutableURLRequest = [[NSMutableURLRequest alloc] initWithURL:theURL];
[mutableURLRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];
Some update on this topic, as I was searching for answers myself. This seems to be a rather general error message, with more than one possible reason.
For javascript api, there was a bug fix for empty body on 24 Dec 2012:
- RestXMLClient include Content-Length header for empty bodies https://github.com/aws/aws-sdk-js/issues/15
Recently on IOS 8, there are problems with aggressive (and non-standard) caching, which Amazon does not like. If there was any GetObject before, If-Modified-Since header is sent for subsequent requests for same object/url, even for PUT requests:
- aws-sdk-ios: https://github.com/aws/aws-sdk-ios/issues/40 AWSS3PutObjectRequest Failed on iOS8 Beta 5 with Not Implemented error.
- aws-sdk-js: https://github.com/aws/aws-sdk-js/issues/376 PutObject on IOS 8
as @Alon Burg has pointed out that S3 expects the Content-Length
header to be set. You cant directly use streams (or I didnt figure out how); Fetch
(or node-fetch) when passing in a ReadStream
as the body, it sets the transport-encoding
header to chunked
which S3 does not support (when using putObject
).
The fix is to first convert the ReadStream
to a Buffer
(or string) and pass that as a body which allows fetch
to calculate the Content-Length
behind the door
I had this problem in Perl with CPAN's Net::Amazon::S3::Client. I examined the request and response and I pieced together the problem, which was that I lacked the ability to request via HTTPS. I fixed it by installing LWP::Protocol::https.
I too faced this problem , while implementing putObject in node js code , and found that i didn't stringfy the JSON body , which resulted in the same error.
精彩评论