Page updated Dec 7, 2023

Download files

Download to file

If you uploaded the data using the key ExampleKey, you can retrieve the data using Amplify.Storage.downloadFile.

Amplify.Storage.downloadFile( "ExampleKey", new File(getApplicationContext().getFilesDir() + "/download.txt"), result -> Log.i("MyAmplifyApp", "Successfully downloaded: " + result.getFile().getName()), error -> Log.e("MyAmplifyApp", "Download Failure", error) );
1Amplify.Storage.downloadFile(
2 "ExampleKey",
3 new File(getApplicationContext().getFilesDir() + "/download.txt"),
4 result -> Log.i("MyAmplifyApp", "Successfully downloaded: " + result.getFile().getName()),
5 error -> Log.e("MyAmplifyApp", "Download Failure", error)
6);

Track download progress

To track progress of the download, use the downloadFile API that includes a progress listener callback.

Amplify.Storage.downloadFile( "ExampleKey", new File(getApplicationContext().getFilesDir() + "/download.txt"), StorageDownloadFileOptions.defaultInstance(), progress -> Log.i("MyAmplifyApp", "Fraction completed: " + progress.getFractionCompleted()), result -> Log.i("MyAmplifyApp", "Successfully downloaded: " + result.getFile().getName()), error -> Log.e("MyAmplifyApp", "Download Failure", error) );
1Amplify.Storage.downloadFile(
2 "ExampleKey",
3 new File(getApplicationContext().getFilesDir() + "/download.txt"),
4 StorageDownloadFileOptions.defaultInstance(),
5 progress -> Log.i("MyAmplifyApp", "Fraction completed: " + progress.getFractionCompleted()),
6 result -> Log.i("MyAmplifyApp", "Successfully downloaded: " + result.getFile().getName()),
7 error -> Log.e("MyAmplifyApp", "Download Failure", error)
8);

Generate a download URL

You can also retrieve a URL for the object in storage:

Amplify.Storage.getUrl( "ExampleKey", result -> Log.i("MyAmplifyApp", "Successfully generated: " + result.getUrl()), error -> Log.e("MyAmplifyApp", "URL generation failure", error) );
1Amplify.Storage.getUrl(
2 "ExampleKey",
3 result -> Log.i("MyAmplifyApp", "Successfully generated: " + result.getUrl()),
4 error -> Log.e("MyAmplifyApp", "URL generation failure", error)
5);