list

Bun

Symbol

S3Client.list

list(input?: null | S3ListObjectsOptions, options?: Pick<S3Options, 'accessKeyId' | 'secretAccessKey' | 'sessionToken' | 'region' | 'bucket' | 'endpoint'>): Promise<S3ListObjectsResponse>

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.

@param input

Options for listing objects in the bucket

@param options

Additional S3 options to override defaults

@returns

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,
      });
    }

Referenced types

interface S3ListObjectsOptions

  • continuationToken?: string

    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.

  • delimiter?: string

    A delimiter is a character that you use to group keys.

  • encodingType?: 'url'

    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.

  • fetchOwner?: boolean

    If you want to return the owner field with each key in the result, then set the FetchOwner field to true.

  • maxKeys?: number

    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.

  • prefix?: string

    Limits the response to keys that begin with the specified prefix.

  • startAfter?: string

    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.

interface S3Options

Configuration options for S3 operations

  • accessKeyId?: string

    The access key ID for authentication. Defaults to S3_ACCESS_KEY_ID or AWS_ACCESS_KEY_ID environment variables.

  • acl?: 'private' | 'public-read' | 'public-read-write' | 'aws-exec-read' | 'authenticated-read' | 'bucket-owner-read' | 'bucket-owner-full-control' | 'log-delivery-write'

    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"
        });
    
  • bucket?: string

    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" });
    
  • endings?: EndingType
  • endpoint?: string

    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"
        });
    
  • partSize?: number

    The size of each part in multipart uploads (in bytes).

    • Minimum: 5 MiB
    • Maximum: 5120 MiB
    • Default: 5 MiB
    // 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
    
  • queueSize?: number

    Number of parts to upload in parallel for multipart uploads.

    • Default: 5
    • Maximum: 255

    Increasing this value can improve upload speeds for large files but will use more memory.

  • region?: string

    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"
        });
    
  • retry?: number

    Number of retry attempts for failed uploads.

    • Default: 3
    • Maximum: 255
    // Setting retry attempts
        const file = s3.file("my-file.txt", {
          retry: 5 // Retry failed uploads up to 5 times
        });
    
  • secretAccessKey?: string

    The secret access key for authentication. Defaults to S3_SECRET_ACCESS_KEY or AWS_SECRET_ACCESS_KEY environment variables.

  • sessionToken?: string

    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
        });
    
  • storageClass?: 'STANDARD' | 'DEEP_ARCHIVE' | 'EXPRESS_ONEZONE' | 'GLACIER' | 'GLACIER_IR' | 'INTELLIGENT_TIERING' | 'ONEZONE_IA' | 'OUTPOSTS' | 'REDUCED_REDUNDANCY' | 'SNOW' | 'STANDARD_IA'

    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"
        });
    
  • type?: string

    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"
        });
    
  • virtualHostedStyle?: boolean

    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"
        });
    

interface S3ListObjectsResponse

  • commonPrefixes?: { prefix: string }[]

    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.

  • contents?: { checksumAlgorithm: 'CRC32' | 'CRC32C' | 'SHA1' | 'SHA256' | 'CRC64NVME'; checksumType: 'COMPOSITE' | 'FULL_OBJECT'; eTag: string; key: string; lastModified: string; owner: { displayName: string; id: string }; restoreStatus: { isRestoreInProgress: boolean; restoreExpiryDate: string }; size: number; storageClass: 'STANDARD' | 'DEEP_ARCHIVE' | 'EXPRESS_ONEZONE' | 'GLACIER' | 'GLACIER_IR' | 'INTELLIGENT_TIERING' | 'ONEZONE_IA' | 'OUTPOSTS' | 'REDUCED_REDUNDANCY' | 'SNOW' | 'STANDARD_IA' }[]

    Metadata about each object returned.

  • continuationToken?: string

    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.

  • delimiter?: string

    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.

  • encodingType?: 'url'

    Encoding type used by S3 to encode object key names in the XML response.

  • isTruncated?: boolean

    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?: number

    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.

  • maxKeys?: number

    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.

  • name?: string

    The bucket name.

  • nextContinuationToken?: string

    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.

  • prefix?: string

    Keys that begin with the indicated prefix.

  • startAfter?: string

    If StartAfter was sent with the request, it is included in the response.