I’m trying to upload an image to Amazon S3 and get a link for the file(Using ASIHTTPRequest for amazon s3). For now I have done the following(my questions are actually in code):
- (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];
}
Okey, I’ve managed to do it myself 🙂
Firstly you should set an access policy which is the property of PUT request
requestForPUTSmth.accessPolicy = ASIS3AccessPolicyPublicReadWrite;
The link for the file is composed in such way:
NSString * linkString = [NSString stringWithFormat:@”http://%@.s3.amazonaws.com/%@”, bucket, key];
Where bucket – is the name of your folder on S3 and Key is the name of file. That’s it.