Options<S, N>: {
    acl?: ObjectCannedACL;
    aws?: {
        accessKeyId?: string;
        bucket?: string;
        endpoint?: string;
        region?: string;
        secretAccessKey?: string;
    };
    deleteFiles?: boolean;
    fieldname: TColumnName<S, N>;
    objectKeyFromRecord?: {
        extraDependencies?: TFieldName<S, N>[];
        mappingFunction: ((record: TPartialSimpleRow<S, N>, context: CollectionCustomizationContext<S, N>) => string | Promise<string>);
    };
    readMode?: "url" | "proxy";
    storeAt?: ((recordId: string, originalFilename: string, context: WriteCustomizationContext<S, N>) => string | Promise<string>);
}

Configuration for the AWS S3 addon of Forest Admin.

It can be included in the global agent configuration under the "s3" key and overriden for specific fields by using the "config" property on AmazonS3File.

Type Parameters

Type declaration

  • Optional acl?: ObjectCannedACL

    Which ACL to use on the uploaded objects. Default is "private" (urls will be signed so that the files can be reached from the frontend).

    Valid values are "authenticated-read", "aws-exec-read", "bucket-owner-full-control", "bucket-owner-read", "private", "public-read", "public-read-write".

    See

    https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/globals.html#objectcannedacl

  • Optional aws?: {
        accessKeyId?: string;
        bucket?: string;
        endpoint?: string;
        region?: string;
        secretAccessKey?: string;
    }

    AWS configuration

    • Optional accessKeyId?: string

      AWS access key, defaults to process.env.AWS_ACCESS_KEY_ID.

    • Optional bucket?: string

      AWS bucket, defaults to process.env.AWS_S3_BUCKET

    • Optional endpoint?: string

      AWS endpoint, defaults to process.env.AWS_S3_ENDPOINT

    • Optional region?: string

      AWS region, defaults to process.env.AWS_DEFAULT_REGION.

    • Optional secretAccessKey?: string

      AWS secret, defaults to process.env.AWS_ACCESS_KEY_SECRET.

  • Optional deleteFiles?: boolean

    Either if old files should be deleted when updating or deleting a record.

  • fieldname: TColumnName<S, N>

    Name of the field that you want to use as a file-picker on the frontend

  • Optional objectKeyFromRecord?: {
        extraDependencies?: TFieldName<S, N>[];
        mappingFunction: ((record: TPartialSimpleRow<S, N>, context: CollectionCustomizationContext<S, N>) => string | Promise<string>);
    }

    This function allows customizing the object key that will be used in S3 without interfering with what is stored in the database.

    Example

    objectKeyFromRecord: {
    extraDependencies: ['firstname', 'lastname'],
    mappingFunction: (record, context) => {
    return `avatars/${record.firstname}-${record.lastname}.png`;
    }
    };
  • Optional readMode?: "url" | "proxy"

    'url' (the default) will cause urls to be transmitted to the frontend. You final users will download the file from S3.

    'proxy' will cause files to be routed by the agent. Use this option only if you are dealing with small files and are behind an entreprise proxy which forbids direct access to S3.

  • Optional storeAt?: ((recordId: string, originalFilename: string, context: WriteCustomizationContext<S, N>) => string | Promise<string>)
      • (recordId: string, originalFilename: string, context: WriteCustomizationContext<S, N>): string | Promise<string>
      • This function allows customizing the string that will be saved in the database. If the objectKeyFromRecord option is not set, the output of that function will also be used as the object key in S3.

        Note that the recordId parameter will not be provided when records are created.

        Defaults to '//`.

        @example

        storeAt: (recordId, originalFilename, context) => {
        return `${context.collection.name}/${recordId ?? 'new-record'}/${originalFilename}`;
        }

        Parameters

        Returns string | Promise<string>