Peer Mohamed Thabib Peer Mohamed Thabib - 1 year ago 267
iOS Question

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;

Answer Source

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:


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download