我通过AFNetworking发布的图像到Amazon S3,并得到一个奇怪的错误。该文件上传,但一旦达到100%,它会返回一个错误:
域= com.alamofire.error.serialization.response code = -1011请求失败:不允许的方法(405)
AFAmazonS3Manager * s3manager = [[AFAmazonS3Manager页头] initWithAccessKeyID:AWS_Access_Key秘密:AWS_Secret_Key]。
s3manager.requestSerializer.region = AFAmazonS3USWest1Region;
s3manager.requestSerializer.bucket = AWS_Bucket_Name;
//设置图像URL名称
的NSString * destionationPathForS3 = @1234567;
[s3manager postObjectWithFile:self.filePath
的DestinationPath:destionationPathForS3
参数:无
进度:^(NSUInteger bytesWritten,长长totalBytesWritten,长长totalBytesExpectedToWrite){
的NSLog(@%F %%上传(totalBytesWritten /(totalBytesExpectedToWrite * 1.0F)* 100));
}
成功:^(ID responseObject){
NSURL * resultURL = [s3manager.requestSerializer.endpointURL URLByAppendingPathComponent:destionationPathForS3]。
的NSLog(@上传完成:%@,resultURL);
}
失败:^(NSError *错误){
的NSLog(@错误:%@,错误);
}];
解决方案
真的不知道为什么,但改变以下为我工作:
postObjectWithFile:
到
putObjectWithFile:
I'm posting an image to Amazon S3 via AFNetworking, and getting a strange error. The file is uploading, but once it hits 100% it returns an error:
Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: method not allowed (405)"
AFAmazonS3Manager *s3manager = [[AFAmazonS3Manager alloc] initWithAccessKeyID:AWS_Access_Key secret:AWS_Secret_Key];
s3manager.requestSerializer.region = AFAmazonS3USWest1Region;
s3manager.requestSerializer.bucket = AWS_Bucket_Name;
//setting for image url name
NSString* destionationPathForS3 = @"1234567";
[s3manager postObjectWithFile:self.filePath
destinationPath:destionationPathForS3
parameters:nil
progress:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"%f%% Uploaded", (totalBytesWritten / (totalBytesExpectedToWrite * 1.0f) * 100));
}
success:^(id responseObject) {
NSURL *resultURL = [s3manager.requestSerializer.endpointURL URLByAppendingPathComponent:destionationPathForS3];
NSLog(@"Upload Complete: %@", resultURL);
}
failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
解决方案
Not really sure why, but changing the below worked for me:
postObjectWithFile:
to
putObjectWithFile: