我正在使用Three20框架编写iPhone应用程序,现在我使用预先签名的URL将图像上传到S3,但还没有成功。
以下是代码
- (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];
}
_key是文件名,例如test.jpg放在
_presignedUrl类似于以下
https://s3.amazonaws.com/<bucket name>/test.jpg?Expires=(expires)&AWSAccessKeyId= (AWSAccessKeyId)&Signature=(Signature)
使用AWS Java SDK在服务器端生成预签名URL,使用GeneratePresignedUrlRequest,test.jpg作为密钥,POST也作为http方法
有什么遗漏或错误吗?