S3 client.

Note: Authentication is handled via OnePasswordClient.

Constructors

Methods

  • When using S3Client.uploadLocalDirectory, a cache is used to skip files that have already been uploaded to S3. Call this method to clear the cache and upload all files in the directory.

    Returns void

  • Upload file content to S3.

    import { S3Client } from '@reuters-graphics/graphics-bin';

    const s3 = new S3Client();

    const fileData = fs.readFileSync('data.json', 'utf8');

    await s3.uploadFile(fileData, 'testfiles/2024/my-project/data.json');

    Parameters

    • fileData: string | Buffer

      File content

    • bucketPath: string

      Path in S3 bucket to upload file to

    • options: S3FileUploadOptions = {}

      File upload options

    Returns Promise<PutObjectCommandOutput | {
        CacheControl: string;
        ContentType: string;
        Body: string | Buffer;
        Bucket: string;
        Key: string;
    }>

  • Upload a local file to S3.

    import { S3Client } from '@reuters-graphics/graphics-bin';

    const s3 = new S3Client();

    await s3.uploadLocalFile('data.json', 'testfiles/2024/my-project/data.json');
    graphics s3:upload data.json testfiles/2024/my-project/data.json

    Description
    Upload a file to S3

    Usage
    $ graphics s3:upload <filePath> <bucketPath> [options]

    Options
    -h, --help Displays this message

    Parameters

    • filePath: string

      Absolute or relative path to a file to upload

    • bucketPath: string

      Path in S3 bucket to upload file to

    • options: S3FileUploadOptions = {}

      File upload options

    Returns Promise<PutObjectCommandOutput | {
        CacheControl: string;
        ContentType: string;
        Body: string | Buffer;
        Bucket: string;
        Key: string;
    }>

  • Upload all files in a local directory to S3.

    import { S3Client } from '@reuters-graphics/graphics-bin';

    const s3 = new S3Client();

    await s3.uploadLocalDirectory('dist', 'testfiles/2024/my-project');
    graphics s3:upload-dir dist testfiles/2024/my-project

    Description
    Upload all files in a directory to S3

    Usage
    $ graphics s3:upload-dir <dirPath> <bucketPath> [options]

    Options
    -h, --help Displays this message

    Parameters

    • dirPath: string

      Absolute or relative path to directory to upload

    • bucketDirPath: string

      Root path in S3 bucket to upload files in the directory to

    • options: S3DirectoryUploadOptions = {}

      Directory upload options

    Returns Promise<(PutObjectCommandOutput | {
        CacheControl: string;
        ContentType: string;
        Body: string | Buffer;
        Bucket: string;
        Key: string;
    })[]>

  • 💀💀💀 DANGEROUSLY delete a directory in S3.

    Note: Directories must be at least 3 levels deep. This method is a no-op in CI environments.

    import { S3Client } from '@reuters-graphics/graphics-bin';

    const s3 = new S3Client();

    await s3.dangerouslyDeleteS3Directory('testfiles/2024/my-project');
    graphics s3:dangerously-delete-dir testfiles/2024/my-project/

    Description
    DANGEROUSLY delete all files in an S3 directory

    Usage
    $ graphics s3:dangerously-delete-dir <bucketPath> [options]

    Options
    -f, --force Do not prompt for confirmation before deleting
    -h, --help Displays this message

    Parameters

    • bucketDirPath: string

      Path to directory to delete, e.g., testfiles/2024/my-project/

    • force: boolean = false

      If true, will not prompt the user to confirm before deleting

    Returns Promise<undefined | {
        Key: string;
    }[]>