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:
1let options = StorageListRequest.Options(pageSize: 1000)2let listResult = try await Amplify.Storage.list(options: options)3listResult.items.forEach { item in4 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
:
1let options = StorageListRequest.Options(accessLevel: .protected, targetIdentityId: "otherUserID", pageSize: 1000)2let listResult = try await Amplify.Storage.list(options: options)3listResult.items.forEach { item in4 print("Key: \(item.key)")5}
If you like limit the response to keys that begin with the specified path provide the path options:
1let options = StorageListRequest.Options(path: "path")2let listResult = try await Amplify.Storage.list(options: options)3listResult.items.forEach { item in4 print("Key: \(item.key)")5}