我正在使用Amazon S3 AFNetworking Client尝试将文件上传到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);
}];
答案 0 :(得分:0)
只是一个猜测,但
AFAmazonS3Client *s3Client = [[AFAmazonS3Client alloc] initWithAccessKeyID:@"kAccessKeyID"
secret:@"kSecret"];
kAccessKeyId / kSecret是常数,是吗?通常,您将常量定义为
#define kAccessKeyId @"myKeyId"
因此,您不希望在它们周围添加其他引号。我真的很惊讶编译器允许它。你的行看起来应该更像
AFAmazonS3Client *s3Client = [[AFAmazonS3Client alloc] initWithAccessKeyID:kAccessKeyID
secret:kSecret];
其他一般调试: