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 Flutter v1 is now in Maintenance Mode until April 30th, 2025. 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 Flutter to get started.

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

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)
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:amplify_storage_s3/amplify_storage_s3.dart';
Future<void> listAlbum() async {
try {
String? nextToken;
bool hasNextPage;
do {
final result = await Amplify.Storage.list(
path: 'album/',
options: StorageListOptions(
accessLevel: StorageAccessLevel.private,
pageSize: 50,
nextToken: nextToken,
pluginOptions: const S3ListPluginOptions(
excludeSubPaths: true,
),
),
).result;
safePrint('Listed items: ${result.items}');
nextToken = result.nextToken;
hasNextPage = result.hasNextPage;
} while (hasNextPage);
} on StorageException catch (e) {
safePrint('Error listing files: ${e.message}');
rethrow;
}
}

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):

import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:amplify_storage_s3/amplify_storage_s3.dart';
Future<void> listAllWithGuestAccessLevel() async {
try {
final result = await Amplify.Storage.list(
options: const StorageListOptions(
accessLevel: StorageAccessLevel.guest,
pluginOptions: S3ListPluginOptions.listAll(),
),
).result;
safePrint('Listed items: ${result.items}');
} on StorageException catch (e) {
safePrint('Error listing files: ${e.message}');
rethrow;
}
}