List file properties
You can list files without having to download all the files. You can do this by using the listFile API from the Amplify Library for Storage. You can also get properties individually for a file using the getProperties API.
List Files
You can list all of the objects uploaded under a given path 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.
let options = StorageListRequest.Options(pageSize: 1000)let listResult = try await Amplify.Storage.list( path: .fromString("public/example/path"), options: options)listResult.items.forEach { item in print("Path: \(item.path)")}
let sink = Amplify.Publisher.create { let options = StorageListRequest.Options(pageSize: 1000) try await Amplify.Storage.list( path: .fromString("public/example/path"), options: options )}.sink { if case let .failure(error) = $0 { print("Failed: \(error)") }}receiveValue: { listResult in print("Completed") listResult.items.forEach { item in print("Path: \(item.path)") }}
More list
options
Option | Type | Description |
---|---|---|
pageSize | UInt | Number between 1 and 1,000 that indicates the limit of how many entries to fetch when retrieving file lists from the server |
nextToken | String | String indicating the page offset at which to resume a listing. |