好吧,如果它可以幫助別人,我設法做這種方式:
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