list
The list
method is used to enumerate objects that satisfy the specified conditions.
async function list(
prefix?: string,
options?: {
startAfter?: string;
limit?: number;
}
): Promise<StorageList>;
Reference
Overview
You can query a list of objects starting with "my-data/" by calling the list
method.
import { myStorage } from "#elements";
...
const listResult: StorageList = await myStorage.list("my-data/");
...
Parameters
prefix
: An optional parameter, it restricts the response to the objects that start with a specified prefix. The parameter should start and end with a letter, number, or slash, and the middle can include letters, numbers, dots, slashes, hyphens, or underscores.options
: Optional parametersstartAfter
: (optional) Specifies the object for which the method starts returning data, it is generally used for pagination. It should start and end with a letter or a number, and the middle can include letters, numbers, dots, slashes, hyphens, or underscores.limit
: (optional) Sets the maximum number of objects returned in the response, the default is 10, and the maximum is 100.
Returns
The list
method returns a object of StorageList
.
type StorageItem = {
key: string; // The unique identifier string for the object
size: number; // The size of the object in bytes
lastModified: string; // The last modified time of the object, in ISO 8601 format
};
type StorageList = { items: StorageItem[] };
Caveats
- If both
prefix
andstartAfter
are specified, ensure thatstartAfter
starts exactly with theprefix
parameter; otherwise, it will be viewed as an invalid parameter combination.