开发者

how to use amazon pre-signed URL

I am trying to download image from Amazon using pre-signed URL. Here is the code, but something must be missing and the image did not show. Thanks in advance!

//Set up the request
S3GetPreSignedURLRequest * request = [[S3GetPreSignedURLRequest alloc] init];
request.bucket = @"a";
request.key = @"b";
request.contentType = @"image/jpeg";
request.httpVerb = @"GET"; 

//set credential
AmazonCredentials * credentials = [[AmazonCredentials alloc] initWithAccessKey:ACCESS_KEY withSecretKey:SECRET_KEY];
request.credentials = credentials;

//set expire
NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
[components setHour:1];
NSDate * oneHourFromNow = [[NSCalendar c开发者_高级运维urrentCalendar] dateByAddingComponents:components toDate:[NSDate date] options:0];

request.expires = oneHourFromNow;

//get the presigned URL
NSURL * url = [[Constants s3] getPreSignedURL: request];


The expire takes UTC time, not a local time.


If somebody is looking for using pre-signed URL using Amazon CloudFront, you may find the following link very useful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜