Forest Admin - API reference
    Preparing search index...

    Type Alias Options<S, N>

    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 Options<
        S extends TSchema = TSchema,
        N extends TCollectionName<S> = TCollectionName<S>,
    > = {
        acl?: ObjectCannedACL;
        aws?: {
            accessKeyId?: string;
            bucket?: string;
            endpoint?: string;
            forcePathStyle?: boolean;
            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>;
    }

    Type Parameters

    Index

    Properties

    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".

    aws?: {
        accessKeyId?: string;
        bucket?: string;
        endpoint?: string;
        forcePathStyle?: boolean;
        region?: string;
        secretAccessKey?: string;
    }

    AWS configuration

    Type Declaration

    • OptionalaccessKeyId?: string

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

    • Optionalbucket?: string

      AWS bucket, defaults to process.env.AWS_S3_BUCKET

    • Optionalendpoint?: string

      AWS endpoint, defaults to process.env.AWS_S3_ENDPOINT

    • OptionalforcePathStyle?: boolean

      AWS forcePathStyle, defauls to false

    • Optionalregion?: string

      AWS region, defaults to process.env.AWS_DEFAULT_REGION.

    • OptionalsecretAccessKey?: string

      AWS secret, defaults to process.env.AWS_ACCESS_KEY_SECRET.

    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

    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.

    objectKeyFromRecord: {
    extraDependencies: ['firstname', 'lastname'],
    mappingFunction: (record, context) => {
    return `avatars/${record.firstname}-${record.lastname}.png`;
    }
    };
    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.

    storeAt?: (
        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 '//`.

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