Page updated Jan 16, 2024

List files

You can list all of the objects uploaded under a given prefix by setting the pageSize. If the pageSize is set lower than the total file size available, A single Storage.list call only returns a subset of all the files. To list all the files with multiple calls, the user can use the nextToken from the previous call response.

This will list all public files:

1StoragePagedListOptions options = StoragePagedListOptions.builder()
2 .setPageSize(1000)
3 .build();
4
5Amplify.Storage.list(
6 "",
7 options,
8 result -> {
9 for (StorageItem item : result.getItems()) {
10 Log.i("MyAmplifyApp", "Item: " + item.getKey());
11 }
12 Log.i("MyAmplifyApp", "Next Token: " + result.getNextToken());
13 },
14 error -> Log.e("MyAmplifyApp", "List failure", error);
15);
1val options = StoragePagedListOptions.builder()
2 .setPageSize(1000)
3 .build()
4
5Amplify.Storage.list("", options,
6 { result ->
7 result.items.forEach { item ->
8 Log.i("MyAmplifyApp", "Item: ${item.key}")
9 }
10 Log.i("MyAmplifyApp", "Next Token: ${result.nextToken}")
11 },
12 { Log.e("MyAmplifyApp", "List failure", it) }
13)
1val options = StoragePagedListOptions.builder()
2 .setPageSize(1000)
3 .build()
4
5try {
6 val result = Amplify.Storage.list("", options)
7 result.items.forEach {
8 Log.i("MyAmplifyApp", "Item: $it")
9 }
10 Log.i("MyAmplifyApp", "next token: ${result.nextToken}")
11} catch (error: StorageException) {
12 Log.e("MyAmplifyApp", "List failure", error)
13}
1StoragePagedListOptions options = StoragePagedListOptions.builder()
2 .setPageSize(1000)
3 .build();
4
5RxAmplify.Storage.list("", options)
6 .subscribe(
7 result -> {
8 for (StorageItem item : result.getItems()) {
9 Log.i("MyAmplifyApp", "Item: " + item.getKey());
10 }
11 Log.i("MyAmplifyApp", "Next Token: " + result.getNextToken());
12 },
13 error -> Log.e("MyAmplifyApp", "List failure", error);
14 );
Note: The range of pageSize can be from 1 - 1000.

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:

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