我正在尝试将图像上传到Amazon S3并获取该文件的链接(对亚马逊s3使用ASIHTTPRequest)。现在我已经完成了以下操作(我的问题实际上是在代码中):
- (void) uploadAnImageToS3 {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[ASIS3Request setSharedSecretAccessKey:@"*****here I put my secretkey*****"];
[ASIS3Request setSharedAccessKey:@"*****here I put my key*****"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(self.imageToPost)];
NSString * key = @"aKey"
ASIS3ObjectRequest *request = [ASIS3ObjectRequest PUTRequestForData:imageData withBucket:@"theBucketName" key:key];
[request setShouldCompressRequestBody:YES];
[request startSynchronous];
if (![request error]) {
//Here I should share a link for the put file, how do I get it? Is there any response from s3?
}
else {
NSLog(@"%@",[[request error] localizedDescription]);
}
[self performSelectorOnMainThread:@selector(stopActivity) withObject:self waitUntilDone:YES];
[pool release];
}
答案 0 :(得分:6)
requestForPUTSmth.accessPolicy = ASIS3AccessPolicyPublicReadWrite;
该文件的链接以这样的方式组成:
NSString * linkString = [NSString stringWithFormat:@“http://%@.s3.amazonaws.com /%@”,bucket,key];
其中bucket - 是S3上文件夹的名称,Key是文件名。就是这样。
答案 1 :(得分:1)
按顺序回答您的问题:
key
变量是文件在S3中的名称。文件由桶中的密钥标识,密钥必须是唯一的 - 认为它们有点像文件名,但只有一级文件夹(桶)。startSynchronous
方法返回),您似乎可以访问请求的responseData
或responseString
属性,以获取S3提供的任何返回数据