如何使用亚马逊预签名网址

时间:2011-06-07 17:50:58

标签: objective-c amazon-s3

我正在尝试使用预先签名的网址从亚马逊下载图片。这是代码,但必须缺少某些内容并且图像没有显示。提前谢谢!

//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 currentCalendar] dateByAddingComponents:components toDate:[NSDate date] options:0];

request.expires = oneHourFromNow;

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

2 个答案:

答案 0 :(得分:2)

expire需要UTC时间,而不是当地时间。

答案 1 :(得分:0)

如果有人正在寻找使用Amazon CloudFront的预签名网址,您可能会找到following link very useful

相关问题