【问题标题】:Post request Amazon S3 with AFNetworking使用 AFNetworking 发布请求 Amazon S3
【发布时间】:2015-01-17 08:56:09
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    不太清楚为什么,但更改以下内容对我有用:

    postObjectWithFile:
    

    putObjectWithFile:
    

    【讨论】:

    • Bucket 公共“WRITE”访问:这有时被称为“put”或“upload”访问。它允许任何人在您的 Amazon S3 存储桶中添加/删除/替换对象。详情-aws.amazon.com/articles/Amazon-S3/5050
    猜你喜欢
    • 1970-01-01
    • 2011-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多