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

Page updated May 2, 2024

List files

You can list all files uploaded under a given path.

This will list all files located under path album that:

  • have private access level
  • are in the root of album/ (the result doesn't include files under any sub path)

excludeSubPaths can be used to exclude nested paths. / is used by as the delimiter for nested paths. This can be customized with the delimiter option.

Future<void> listAlbum() async {
try {
String? nextToken;
bool hasNextPage;
do {
final result = await Amplify.Storage.list(
path: const StoragePath.fromString('public/album/'),
options: StorageListOptions(
pageSize: 50,
nextToken: nextToken,
pluginOptions: const S3ListPluginOptions(
excludeSubPaths: true,
delimiter: '/',
),
),
).result;
safePrint('Listed items: ${result.items}');
nextToken = result.nextToken;
hasNextPage = result.hasNextPage;
} while (hasNextPage);
} on StorageException catch (e) {
safePrint(e.message);
}
}

Pagination is enabled by default. The default pageSize is 1000 if it is not set in the StorageListOptions.

You can also list all files under a given path without pagination by using the pluginOptions and S3ListPluginOptions.listAll() constructor.

This will list all public files (i.e. those with guest access level):

Future<void> listAll() async {
try {
final result = await Amplify.Storage.list(
path: const StoragePath.fromString('public/'),
options: const StorageListOptions(
pluginOptions: S3ListPluginOptions.listAll(),
),
).result;
safePrint('Listed items: ${result.items}');
} on StorageException catch (e) {
safePrint(e.message);
}
}