使用AFNetworking发布请求Amazon S3

时间:2015-01-17 08:56:10

标签: objective-c amazon-web-services amazon-s3 afnetworking-2

我通过AFNetworking将图像发布到Amazon S3,并收到一个奇怪的错误。该文件正在上传,但一旦达到100%就会返回错误:

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);
                      }];

1 个答案:

答案 0 :(得分:9)

不确定原因,但改变下面的内容对我有用:

postObjectWithFile:

putObjectWithFile: