0

I am writing an iPhone app using Three20 framework, now I am using presigned url to upload images to S3, but haven't been successful.

The following is the code

- (void)uploadImage {
    TTURLRequest *request = [TTURLRequest requestWithURL:_presignedUrl delegate:self];

    request.httpMethod = @"POST";
    request.cachePolicy = TTURLRequestCachePolicyNoCache; 
    request.cacheExpirationAge = TT_CACHE_EXPIRATION_AGE_NEVER;

    // add the image file
    [request addFile:UIImageJPEGRepresentation(_image, 1.0)
            mimeType:@"image/jpeg" 
            fileName:_key];

    [request setValue:@"MyApp/1.0" forHTTPHeaderField:@"User-Agent"];
    [request setValue:@"image/jpeg" forHTTPHeaderField:@"Content-type"];

    TTURLXMLResponse *response = [[TTURLXMLResponse alloc] init];
    request.response = response;
    [response release];

    [request send];
}

The _key is the file name e.g. test.jpg

The _presignedUrl is something like the following

https://s3.amazonaws.com/<bucket name>/test.jpg?Expires=(expires)&AWSAccessKeyId= (AWSAccessKeyId)&Signature=(Signature)

And the presigned url is generated on Server side using AWS Java SDK by using GeneratePresignedUrlRequest with , test.jpg as key, and also POST as http method

Is there anything missing or wrong?

tom
  • 14,273
  • 19
  • 65
  • 124

0 Answers0