Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Apr 29, 2024

List files

Amplify Android v1 is deprecated as of June 1st, 2024. No new features or bug fixes will be added. Dependencies may become outdated and potentially introduce compatibility issues.

Please use the latest version (v2) of Amplify Library for Android to get started. Refer to the upgrade guide for instructions on upgrading your application to the latest version.

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:

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

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:

StorageListOptions options = StorageListOptions.builder()
.accessLevel(StorageAccessLevel.PROTECTED)
.targetIdentityId("otherUserID")
.build();
Amplify.Storage.list(
"",
options,
result -> {
for (StorageItem item : result.getItems()) {
Log.i("MyAmplifyApp", "Item: " + item.getKey());
}
},
error -> Log.e("MyAmplifyApp", "List failure", error)
);
val options = StorageListOptions.builder()
.accessLevel(StorageAccessLevel.PROTECTED)
.targetIdentityId("otherUserID")
.build()
Amplify.Storage.list("", options,
{ result ->
result.items.forEach { item ->
Log.i("MyAmplifyApp", "Item: ${item.key}")
}
},
{ Log.e("MyAmplifyApp", "List failure", it) }
)
val options = StorageListOptions.builder()
.accessLevel(StorageAccessLevel.PROTECTED)
.targetIdentityId("otherUserID")
.build()
try {
Amplify.Storage.list("", options).items.forEach {
Log.i("AmplifyApplication", "Item: $it")
}
} catch (error: StorageException) {
Log.e("MyAmplifyApp", "List failure", error)
}
StorageListOptions options = StorageListOptions.builder()
.accessLevel(StorageAccessLevel.PROTECTED)
.targetIdentityId("otherUserID")
.build();
RxAmplify.Storage.list("", options)
.subscribe(
result -> {
for (StorageItem item : result.getItems()) {
Log.i("MyAmplifyApp", "Item: " + item.getKey());
}
},
error -> Log.e("MyAmplifyApp", "List failure", error)
);