Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting image URL from bucket Amazon Web Service iOS after uploading

I have an image that I'm uploading to my bucket in AWS this way:

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 uploading the image works just fine. When I open my bucket I see the image there.

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

like image 455
RJiryes Avatar asked Sep 08 '14 14:09

RJiryes


People also ask

What Amazon S3 feature can be used to provide a time limited URL for an object to be uploaded or downloaded?

With Query String Authentication, customers can create a URL to an Amazon S3 object which is only valid for a limited time.

What is a Presigned URL AWS?

A presigned URL is generated by an AWS user who has access to the object. The generated URL is then given to the unauthorized user. The presigned URL can be entered in a browser or used by a program or HTML webpage. The credentials used by the presigned URL are those of the AWS user who generated the URL.


2 Answers

You don't get it, you create it like:

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

like image 91
rptwsthi Avatar answered Oct 01 '22 00:10

rptwsthi


AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];

uploadRequest.body = [NSURL fileURLWithPath:filePath];
uploadRequest.key = fileName;
uploadReuest.bucket = S3BucketName;

[uploadRequest setACL:AWSS3ObjectCannedACLPublicRead];

Above Answer is right but you must have to set "ACL" to uploadRequest.

In your Question,you are forget to set "ACL".

Thanks

like image 28
prish Avatar answered Sep 30 '22 23:09

prish