在iOS中上传Amazon S3 POST

我有服务器生成参数像AWSAccessKeyID,ACL,政策,签名上传文件到S3使用POST像这里: http : //doc.s3.amazonaws.com/proposals/post.html 。 现在有了这些参数,我需要在Amazon服务器上运行这个请求。 似乎我不能使用本机AWS iOS SDK,因为它的S3客户端只能使用存储在服务器上而不是设备上的AWS密钥和秘密进行初始化。

用S3上的所有参数调用这个POST请求上传文件的最佳方法是什么? 或者也许有办法使用AWS SDK。

好的,如果有人帮忙,我就这样做了:

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" //NB! To post to S3 name should be "file", not real file name fileName:@"your_filename" mimeType:@"mime/type"]; }]; AFHTTPRequestOperation* operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; 

如果需要,您可以使用任何其他types的操作(如AFXMLRequestOperation),因为S3以XML格式返回响应。

如果有任何参数丢失或包含无效数据 – 请求将不被接受。

这里是一个链接到这个背景信息: 浏览器上传到S3使用HTML POST表单