Retrieving the image URL from the Amazon Web Service iOS recycle bin after upload

I have an image that I upload to my bucket in AWS like this:

BFTask *task = [BFTask taskWithResult:nil]; [[task continueWithBlock:^id(BFTask *task) { self.URL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"test"]]; NSData *data = UIImagePNGRepresentation(image); //NSMutableString *dataString = [NSMutableString new]; [data writeToURL:self.URL atomically:YES]; return nil; }]continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task) { self.uploadRequest1 = [AWSS3TransferManagerUploadRequest new]; self.uploadRequest1.bucket = S3BucketName; self.uploadRequest1.key = S3KeyUploadName1; self.uploadRequest1.body = self.URL; return nil; }]; AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager]; [[transferManager upload:self.uploadRequest1] continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task) { if (task.error != nil) { if( task.error.code != AWSS3TransferManagerErrorCancelled && task.error.code != AWSS3TransferManagerErrorPaused ) { NSLog(@"Upload Failed!"); } } else { self.uploadRequest1 = nil; NSLog(@"Uploaded!"); } return nil; }]; 

The code for loading the image works fine. When I open my bucket, I see an image there.

Now, what I want to do is get the URL of this image, is there a way to get the URL without getting the image again?

+5
source share
3 answers

You do not understand, you create it as:

https://s3.amazonaws.com/BUCKET_NAME/FILE_NAME.jpg

+6
source
 AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new]; uploadRequest.body = [NSURL fileURLWithPath:filePath]; uploadRequest.key = fileName; uploadReuest.bucket = S3BucketName; 

[uploadRequest setACL: AWSS3ObjectCannedACLPublicRead];

The above answer is right, but you need to set an "ACL" for uploadRequest.

In your question, you forgot to set the "ACL".

thanks

+4
source

I managed to get the path from Amazon S3 -> Bucket -> Folder -> Image file -> Properties and on the right side, you will see something like this.

Get an affordable way from here.

+2
source

Source: https://habr.com/ru/post/1202078/


All Articles