Home » Education » How to download an image file from AWS S3 using signed URL in your Android App?

How to download an image file from AWS S3 using signed URL in your Android App?

Written By Programmer World on Monday, Jun 05, 2023 | 03:15 PM

 
In this video it shows the steps for downloading an image file from AWS (Amazon Web Services) S3 (Amazon Simple Storage Service) in your Android App. It uses the signed URL of the file which is valid for a limited period (max 12 hours). In this demo the signed URL was generated with a validity of 1 hour post which the URL would expire. Signed URL is a publicly accessible URL for any resource on S3. I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: [email protected] Complete source code and other details/ steps of this video are posted in the below link: https://programmerworld.co/android/how-to-download-an-image-file-from-aws-s3-using-signed-url-in-your-android-app/ However, the main Java code is copied below also for reference: package com.programmerworld.imagefilefromawss3; import androidx.appcompat.app.AppCompatActivity; import android.app.DownloadManager; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.view.View; import android.widget.TextView; import java.net.URI; public class MainActivity extends AppCompatActivity { private String stringSignedURL = "https://sampleimagefile.s3.ap-south-1.amazonaws.com/flower.jpg?response-content-disposition=inline&X-Amz-Security-Token=IQoJbxxxxxxxx"; private TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView = findViewById(R.id.textView); } public void buttonDownload(View view){ DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); Uri uri = Uri.parse(stringSignedURL); DownloadManager.Request request = new DownloadManager.Request(uri); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "ImageAWS_S3.jpg"); downloadManager.enqueue(request); textView.setText("SUCCESS"); } }