Page updated Nov 16, 2023

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:

let options = StorageListRequest.Options(pageSize: 1000) let listResult = try await Amplify.Storage.list(options: options) listResult.items.forEach { item in print("Key: \(item.key)") }
1let options = StorageListRequest.Options(pageSize: 1000)
2let listResult = try await Amplify.Storage.list(options: options)
3listResult.items.forEach { item in
4 print("Key: \(item.key)")
5}

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:

let options = StorageListRequest.Options(accessLevel: .protected, targetIdentityId: "otherUserID", pageSize: 1000) let listResult = try await Amplify.Storage.list(options: options) listResult.items.forEach { item in print("Key: \(item.key)") }
1let options = StorageListRequest.Options(accessLevel: .protected, targetIdentityId: "otherUserID", pageSize: 1000)
2let listResult = try await Amplify.Storage.list(options: options)
3listResult.items.forEach { item in
4 print("Key: \(item.key)")
5}

If you like limit the response to keys that begin with the specified path provide the path options:

let options = StorageListRequest.Options(path: "path") let listResult = try await Amplify.Storage.list(options: options) listResult.items.forEach { item in print("Key: \(item.key)") }
1let options = StorageListRequest.Options(path: "path")
2let listResult = try await Amplify.Storage.list(options: options)
3listResult.items.forEach { item in
4 print("Key: \(item.key)")
5}