List files
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) );