Download Amazon S3 POST on iOS

I have a server that generates parameters such as AWSAccessKeyID, acl, policy, signature for uploading a file to S3 using POST, like here: http://doc.s3.amazonaws.com/proposals/post.html . Now, having these parameters, I need to somehow run this request on the Amazon server. It seems that I can’t use my own AWS iOS SDK, because its S3 client can only be initialized with the AWS key and secrets, which are stored on the server and not on the device.

What is the best way to invoke this POST request with all S3 parameters to download the file? Or maybe there are ways to use the AWS SDK for this.

+5
source share
1 answer

, - , :

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.

- - .

: S3 HTML POST-

+18

All Articles