好吧,如果它可以帮助别人,我设法做这种方式:
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
在这里看到:http://stackoverflow.com/questions/5537297/ios-how-to-perform-a-http-post-request – 2013-02-12 17:23:55
谢谢。我认为我的问题很愚蠢,在问之前我必须考虑。我设法使用AFNetworking上传文件。 – 2013-02-14 01:45:35
如果别人有同样的问题,您应该发布自己的解决方案作为答案。 – 2013-02-14 02:25:37