我試圖將圖像上傳到Amazon S3並獲取該文件的鏈接(使用ASIHTTPRequest進行亞馬遜S3)。現在我已經做了以下(我的問題實際上是代碼):如何將文件上傳到amazon s3並獲取鏈接?
- (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];
}
哦,我討厭沒有評論的downvotes! :(如果你很聰明,你爲什麼不回答這個問題? – Stas 2012-03-01 19:38:41