Download files
Download to file
If you uploaded the data using the key ExampleKey
, you can retrieve the data using Amplify.Storage.downloadFile
.
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.
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:
1Amplify.Storage.getUrl(2 "ExampleKey",3 result -> Log.i("MyAmplifyApp", "Successfully generated: " + result.getUrl()),4 error -> Log.e("MyAmplifyApp", "URL generation failure", error)5);