AFAmazonS3Client
是一个用于与 Amazon S3 API 交互的 AFHTTPRequestOperationManager
子类。
由于 S3 API 返回 XML 响应,您可能希望将 AFOnoResponseSerializer 设置为响应序列化器。
AFAmazonS3Manager *s3Manager = [[AFAmazonS3Manager alloc] initWithAccessKeyID:@"..." secret:@"..."];
s3manager.requestSerializer.region = AFAmazonS3USWest1Region;
s3manager.requestSerializer.bucket = @"my-bucket-name";
NSString *destinationPath = @"/pathOnS3/to/file.txt";
[s3Manager postObjectWithFile:@"/path/to/file.txt"
destinationPath:destinationPath
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:destinationPath];
NSLog(@"Upload Complete: %@", resultURL);
}
failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
Mattt Thompson
AFAmazonS3Client 可在 MIT 许可下使用。请参阅 LICENSE 文件以获取更多信息。