好的,如果它对某人有帮助,我设法做到了:
NSDictionary* parametersDictionary = @{@"AWSAccessKeyId" : @"YOUR_KEY",
@"acl" : @"public-read", // or whatever you need
@"key" : @"filename.ext", // file name on server, without leading /
@"policy" : @"YOUR_POLICY_DOCUMENT_BASE64_ENCODED",
@"signature" : @"YOUR_CALCULATED_SIGNATURE"
};
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString: @"http://s3-bucket.s3.amazonaws.com"]];
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST"
path:nil
parameters:parametersDictionary
constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
[formData appendPartWithFileData:fileData
name:@"file" //N.B.! To post to S3 name should be "file", not real file name
fileName:@"your_filename"
mimeType:@"mime/type"];
}];
AFHTTPRequestOperation* operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
如果需要,您可以使用任何其他类型的操作,例如 AFXMLRequestOperation,因为 S3 以 XML 格式返回响应。
如果任何参数丢失或包含无效数据 - 请求将不被接受。
以下是相关背景信息的链接:Browser Uploads to S3 using HTML POST Forms