我正在使用Amazon S3 AFNetworking 客户端尝试将文件上传到 S3,但遇到了麻烦。在模拟器中运行时收到错误的 URL 响应,在设备上运行时收到 405 响应。收到 405 响应时,日志表明 100% 的文件已上传。我不确定我是否正确。这是我的代码:
AFAmazonS3Client *s3Client = [[AFAmazonS3Client alloc] initWithAccessKeyID:kAccessKeyID
secret:kSecret];
s3Client.bucket = kBucket;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documents = [paths objectAtIndex:0];
NSString *path = [documents stringByAppendingPathComponent:@"test.jpeg"];
[s3Client postObjectWithFile:path parameters:nil progress:^(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"%f%% Uploaded", (totalBytesWritten / (totalBytesExpectedToWrite * 1.0f) * 100));
} success:^(id responseObject) {
NSLog(@"Upload Complete");
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];