Page updated Jan 16, 2024

List files

Amplify Android v1 is now in Maintenance Mode until May 31st, 2024. This means that we will continue to include updates to ensure compatibility with backend services and security. No new features will be introduced in v1.

Please use the latest version (v2) of Amplify Library for Android to get started.

If you are currently using v1, follow these instructions to upgrade to v2.

Amplify libraries should be used for all new cloud connected applications. If you are currently using the AWS Mobile SDK for Android, you can access the documentation here.

You can list all of the objects uploaded under a given prefix. This will list all public files:

1Amplify.Storage.list("",
2 result -> {
3 for (StorageItem item : result.getItems()) {
4 Log.i("MyAmplifyApp", "Item: " + item.getKey());
5 }
6 },
7 error -> Log.e("MyAmplifyApp", "List failure", error)
8);
1Amplify.Storage.list("",
2 { result ->
3 result.items.forEach { item ->
4 Log.i("MyAmplifyApp", "Item: ${item.key}")
5 }
6 },
7 { Log.e("MyAmplifyApp", "List failure", it) }
8)
1try {
2 Amplify.Storage.list("").items.forEach {
3 Log.i("MyAmplifyApp", "Item: ${it.key}")
4 }
5} catch (error: StorageException) {
6 Log.e("MyAmplifyApp", "List failure", error)
7}
1RxAmplify.Storage.list("")
2 .subscribe(
3 result -> {
4 for (StorageItem item : result.getItems()) {
5 Log.i("MyAmplifyApp", "Item: " + item.getKey());
6 }
7 },
8 error -> Log.e("MyAmplifyApp", "List failure", error)
9 );

You can also list private or protected files by passing options. For example, to list all protected files owned by a user identified by the ID otherUserID:

1StorageListOptions options = StorageListOptions.builder()
2 .accessLevel(StorageAccessLevel.PROTECTED)
3 .targetIdentityId("otherUserID")
4 .build();
5
6Amplify.Storage.list(
7 "",
8 options,
9 result -> {
10 for (StorageItem item : result.getItems()) {
11 Log.i("MyAmplifyApp", "Item: " + item.getKey());
12 }
13 },
14 error -> Log.e("MyAmplifyApp", "List failure", error)
15);
1val options = StorageListOptions.builder()
2 .accessLevel(StorageAccessLevel.PROTECTED)
3 .targetIdentityId("otherUserID")
4 .build()
5
6Amplify.Storage.list("", options,
7 { result ->
8 result.items.forEach { item ->
9 Log.i("MyAmplifyApp", "Item: ${item.key}")
10 }
11 },
12 { Log.e("MyAmplifyApp", "List failure", it) }
13)
1val options = StorageListOptions.builder()
2 .accessLevel(StorageAccessLevel.PROTECTED)
3 .targetIdentityId("otherUserID")
4 .build()
5
6try {
7 Amplify.Storage.list("", options).items.forEach {
8 Log.i("AmplifyApplication", "Item: $it")
9 }
10} catch (error: StorageException) {
11 Log.e("MyAmplifyApp", "List failure", error)
12}
1StorageListOptions options = StorageListOptions.builder()
2 .accessLevel(StorageAccessLevel.PROTECTED)
3 .targetIdentityId("otherUserID")
4 .build();
5
6RxAmplify.Storage.list("", options)
7 .subscribe(
8 result -> {
9 for (StorageItem item : result.getItems()) {
10 Log.i("MyAmplifyApp", "Item: " + item.getKey());
11 }
12 },
13 error -> Log.e("MyAmplifyApp", "List failure", error)
14 );