Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload a file to Amazon S3 and get the url in response using iOS

I have used the code snippet from Amazon Sample Code. The below code uploads the data into amazon S3 bucket, but I need the URL of the upload file. Am i going in the right direction? or could someone point me the mistake I am making

Any kind of help would be greatly appreciated.

AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
    AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
    uploadRequest.bucket = S3BucketName;
    uploadRequest.key = S3UploadKeyName;
    uploadRequest.body = self.uploadFileURL;
    //uploadRequest.contentLength = [NSNumber numberWithUnsignedLongLong:fileSize];

    [[transferManager upload:uploadRequest] continueWithBlock:^id(BFTask *task) {
        // Do something with the response
        AWSS3TransferManagerUploadOutput *uploadOutPut = task.result;
        NSLog(@"bftask:%@",uploadOutPut); // Upload out put gives me the following response
        return nil;
    }];

bfTask Response:

bftask:<AWSS3TransferManagerUploadOutput: 0x1706606c0> {
    ETag = "\"0aefedfa36b687a74025b1ad50f3101f\"";
    serverSideEncryption = 0;
}
like image 489
Peer Mohamed Thabib Avatar asked May 08 '15 08:05

Peer Mohamed Thabib


1 Answers

If you just need to download the file, you can use AWSS3TransferManagerDownloadRequest to download a file using the SDK. Alternatively, you can use AWSS3PreSignedURLBuilder to generate a pre-signed URL to download a file.

If you just want to know the URL of the object, the URL follows the following pattern:

https://<YourS3Endpoint>/<YourBucketName>/<YourObjectKeyName>

Any objects in Amazon S3 are private by default and not publicly readable. If you want to make it publicly readable, you need to set ACL on your AWSS3TransferManagerUploadRequest object.

See Amazon S3 Bucket Public Access Considerations for more details.

like image 97
Yosuke Matsuda Avatar answered Sep 22 '22 02:09

Yosuke Matsuda