Returns some or all (up to 1,000) of the objects in a bucket with each request.
You can use the request parameters as selection criteria to return a subset of the objects in a bucket.
Symbol
Returns some or all (up to 1,000) of the objects in a bucket with each request.
You can use the request parameters as selection criteria to return a subset of the objects in a bucket.
Options for listing objects in the bucket
Additional S3 options to override defaults
A promise that resolves to the list response
// List (up to) 1000 objects in the bucket
const allObjects = await bucket.list();
// List (up to) 500 objects under `uploads/` prefix, with owner field for each object
const uploads = await bucket.list({
prefix: 'uploads/',
maxKeys: 500,
fetchOwner: true,
});
// Check if more results are available
if (uploads.isTruncated) {
// List next batch of objects under `uploads/` prefix
const moreUploads = await bucket.list({
prefix: 'uploads/',
maxKeys: 500,
startAfter: uploads.contents!.at(-1).key
fetchOwner: true,
});
}
ContinuationToken indicates to S3 that the list is being continued on this bucket with a token. ContinuationToken is obfuscated and is not a real key. You can use this ContinuationToken for pagination of the list results.
Encoding type used by S3 to encode the object keys in the response. Responses are encoded only in UTF-8. An object key can contain any Unicode character. However, the XML 1.0 parser can't parse certain characters, such as characters with an ASCII value from 0 to 10. For characters that aren't supported in XML 1.0, you can add this parameter to request that S3 encode the keys in the response.
If you want to return the owner field with each key in the result, then set the FetchOwner field to true.
Sets the maximum number of keys returned in the response. By default, the action returns up to 1,000 key names. The response might contain fewer keys but will never contain more.
StartAfter is where you want S3 to start listing from. S3 starts listing after this specified key. StartAfter can be any key in the bucket.
Configuration options for S3 operations
The access key ID for authentication. Defaults to S3_ACCESS_KEY_ID
or AWS_ACCESS_KEY_ID
environment variables.
The Access Control List (ACL) policy for the file. Controls who can access the file and what permissions they have.
// Setting public read access
const file = s3.file("public-file.txt", {
acl: "public-read",
bucket: "my-bucket"
});
The S3 bucket name. Defaults to S3_BUCKET
or AWS_BUCKET
environment variables.
// Using explicit bucket
const file = s3.file("my-file.txt", { bucket: "my-bucket" });
The S3-compatible service endpoint URL. Defaults to S3_ENDPOINT
or AWS_ENDPOINT
environment variables.
// AWS S3
const file = s3.file("my-file.txt", {
endpoint: "https://s3.us-east-1.amazonaws.com"
});
The size of each part in multipart uploads (in bytes).
// Configuring multipart uploads
const file = s3.file("large-file.dat", {
partSize: 10 * 1024 * 1024, // 10 MiB parts
queueSize: 4 // Upload 4 parts in parallel
});
const writer = file.writer();
// ... write large file in chunks
Number of parts to upload in parallel for multipart uploads.
Increasing this value can improve upload speeds for large files but will use more memory.
The AWS region. Defaults to S3_REGION
or AWS_REGION
environment variables.
const file = s3.file("my-file.txt", {
bucket: "my-bucket",
region: "us-west-2"
});
Number of retry attempts for failed uploads.
// Setting retry attempts
const file = s3.file("my-file.txt", {
retry: 5 // Retry failed uploads up to 5 times
});
The secret access key for authentication. Defaults to S3_SECRET_ACCESS_KEY
or AWS_SECRET_ACCESS_KEY
environment variables.
Optional session token for temporary credentials. Defaults to S3_SESSION_TOKEN
or AWS_SESSION_TOKEN
environment variables.
// Using temporary credentials
const file = s3.file("my-file.txt", {
accessKeyId: tempAccessKey,
secretAccessKey: tempSecretKey,
sessionToken: tempSessionToken
});
By default, Amazon S3 uses the STANDARD Storage Class to store newly created objects.
// Setting explicit Storage class
const file = s3.file("my-file.json", {
storageClass: "STANDARD_IA"
});
The Content-Type of the file. Automatically set based on file extension when possible.
// Setting explicit content type
const file = s3.file("data.bin", {
type: "application/octet-stream"
});
Use virtual hosted style endpoint. default to false, when true if endpoint
is informed it will ignore the bucket
// Using virtual hosted style
const file = s3.file("my-file.txt", {
virtualHostedStyle: true,
endpoint: "https://my-bucket.s3.us-east-1.amazonaws.com"
});
All of the keys (up to 1,000) that share the same prefix are grouped together. When counting the total numbers of returns by this API operation, this group of keys is considered as one item.
A response can contain CommonPrefixes only if you specify a delimiter.
CommonPrefixes contains all (if there are any) keys between Prefix and the next occurrence of the string specified by a delimiter.
CommonPrefixes lists keys that act like subdirectories in the directory specified by Prefix.
For example, if the prefix is notes/ and the delimiter is a slash (/) as in notes/summer/july, the common prefix is notes/summer/. All of the keys that roll up into a common prefix count as a single return when calculating the number of returns.
Metadata about each object returned.
If ContinuationToken was sent with the request, it is included in the response. You can use the returned ContinuationToken for pagination of the list response.
Causes keys that contain the same string between the prefix and the first occurrence of the delimiter to be rolled up into a single result element in the CommonPrefixes collection. These rolled-up keys are not returned elsewhere in the response. Each rolled-up result counts as only one return against the MaxKeys value.
Set to false if all of the results were returned. Set to true if more keys are available to return. If the number of results exceeds that specified by MaxKeys, all of the results might not be returned.
KeyCount is the number of keys returned with this request. KeyCount will always be less than or equal to the MaxKeys field. For example, if you ask for 50 keys, your result will include 50 keys or fewer.
Sets the maximum number of keys returned in the response. By default, the action returns up to 1,000 key names. The response might contain fewer keys but will never contain more.
NextContinuationToken is sent when isTruncated is true, which means there are more keys in the bucket that can be listed. The next list requests to S3 can be continued with this NextContinuationToken. NextContinuationToken is obfuscated and is not a real key.