How to upload/download files (images) with Amazon S3 Android
Tags: s3, android, amazon, files
Published: 2021-04-28 18:15:34

https://grokonez.com/android/uploaddownload-files-images-amazon-s3-android

How to upload/download files (images) with Amazon S3 Android

Amazon Simple Storage Service (Amazon S3) is object storage built to store and retrieve any amount of data from web or mobile. Amazon S3 is designed to make web-scale computing easier for developers. In this tutorial, we're gonna create an Android App that can upload/download files (images) to/from Amazon S3.

Related Post: <a href="https://grokonez.com/android/integrate-aws-mobile-sdk-android-app">How to integrate AWS Mobile SDK into Android App</a>

<!--more-->
<h2>I. Technology</h2>
- Android Studio 2.x
- AWS Mobile SDK Client 2.6.7
<h2>II. Data Storage with Amazon S3</h2>
<h3>1. Integrate AWS Mobile SDK into Android App</h3>
Please visit <a href="https://grokonez.com/android/integrate-aws-mobile-sdk-android-app">this article</a> for details.
<h3>2. Enable User Data Storage</h3>
Open your project in <a href="https://console.aws.amazon.com/mobilehub" target="_blank" rel="nofollow">Mobile Hub</a> and choose the User Data Storage tile to enable the feature.

<img src="https://grokonez.com/wp-content/uploads/2018/01/amazon-s3-storage-enable.png" alt="amazon-s3-storage-enable" width="699" height="477" class="alignnone size-full wp-image-10398" />

Choose <strong>Store user data</strong> and click on <strong>Save</strong> button:

<img src="https://grokonez.com/wp-content/uploads/2018/01/amazon-s3-storage-enable-save.png" alt="amazon-s3-storage-enable-save" width="699" height="383" class="alignnone size-full wp-image-10399" />
<h3>3. Updated latest cloud configuration file</h3>
Return to the project details page, click on <strong>Integrate</strong> button:

<img src="https://grokonez.com/wp-content/uploads/2018/01/amazon-s3-storage-integrate.png" alt="amazon-s3-storage-integrate" width="500" height="365" class="alignnone size-full wp-image-10400" />

Download new Cloud Config file, then override it in <<strong>project</strong>>/<strong>app</strong>/<strong>src</strong>/<strong>main</strong>/<strong>res</strong>/<strong>raw</strong>:

<img src="https://grokonez.com/wp-content/uploads/2018/01/amazon-s3-storage-upadte-config-file.png" alt="amazon-s3-storage-upadte-config-file" width="698" height="332" class="alignnone size-full wp-image-10401" />
<h3>4. Create an IAM user</h3>
We need to provide access permission mobile bucket. So follow these step to create an IAM user and get <strong>Access key ID</strong> and <strong>Secret access key</strong>:

Go to <code>https://console.aws.amazon.com/iam/</code>
In the navigation pane, choose <strong>Users</strong> and then choose <strong>Add user</strong>.

<img src="https://grokonez.com/wp-content/uploads/2017/07/amazon-s3-starter-choose-user.png" alt="springboot amazon s3 starter - choose user" width="434" height="307" class="alignnone size-full wp-image-6965" />

Input <strong>User name</strong>, choose <strong>Programmatic access</strong> for <strong>Access type</strong>:

<img src="https://grokonez.com/wp-content/uploads/2017/07/amazon-s3-starter-add-user-info-1.png" alt="amazon s3 starter - add user info" width="700" height="444" class="alignnone size-full wp-image-6974" />

Press <strong>Next: Permissions</strong> button -> go to <strong>Set permissions for jsa-user</strong> screen.
Now, choose <strong>Attach existing policies directly</strong> -> filter policy type <strong>s3</strong>, then check <strong>AmazonS3FullAccess</strong>:

<img src="https://grokonez.com/wp-content/uploads/2017/07/amazon-s3-starter-add-policies.png" alt="amazon s3 starter - add policies" width="704" height="670" class="alignnone size-full wp-image-6967" />

Press <strong>Next: Review</strong>:

<img src="https://grokonez.com/wp-content/uploads/2017/07/amazon-s3-starter-review-policies.png" alt="amazon s3 starter - review policies" width="732" height="439" class="alignnone size-full wp-image-6968" />

Press <strong>Create user</strong>:

<img src="https://grokonez.com/wp-content/uploads/2017/07/amazon-s3-starter-got-access-key.png" alt="" width="761" height="367" class="alignnone size-full wp-image-6972" />

Press <strong>Download .csv</strong> for {<strong>Access key ID</strong>, <strong>Secret access key</strong>}.
<h3>5. Connect to Amazon S3</h3>
<h4>5.1 Add dependencies</h4>
Open <strong>app</strong>/<strong>build.gradle</strong>, add:

More at:

https://grokonez.com/android/uploaddownload-files-images-amazon-s3-android

How to upload/download files (images) with Amazon S3 Android