Post request Amazon S3 with AFNetworking

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

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

回答1:

Not really sure why, but changing the below worked for me:

postObjectWithFile: 

to

putObjectWithFile: 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!