naystack - v1.9.9
    Preparing search index...

    Interface SetupFileUploadOptions

    Options for setting up file upload via setupFileUpload.

    Every callback receives the same { type, userId, data } context. data is optional — it is whatever the caller passed as config.data to useFileUpload, and the client only appends the form field when a value is given, so the route parses it to undefined otherwise. Narrow it before use; destructuring it unguarded throws at runtime.

    interface SetupFileUploadOptions {
        getKey?: (
            data: { data?: object; type: string; userId: number },
        ) => Promise<string>;
        onUpload: (
            data: {
                data?: object;
                type: string;
                url: string | null;
                userId: number;
            },
        ) => Promise<object>;
        processFile?: (
            file: File,
            data: { data?: object; type: string; userId: number },
        ) => Promise<Blob>;
        putOptions?: (
            data: { data?: object; type: string; userId: number },
        ) => PutOverrides;
    }
    Index

    Properties

    getKey?: (
        data: { data?: object; type: string; userId: number },
    ) => Promise<string>

    Optional. Given { type, userId, data }, returns the S3 object key for the upload. If omitted, a UUID is generated.

    onUpload: (
        data: {
            data?: object;
            type: string;
            url: string | null;
            userId: number;
        },
    ) => Promise<object>

    Required. Called after each successful upload with { url, type, userId, data }. The return value is included in the API response as onUploadResponse (e.g. save metadata to your database and return it).

    processFile?: (
        file: File,
        data: { data?: object; type: string; userId: number },
    ) => Promise<Blob>

    Optional. Given the uploaded file and { type, userId, data }, returns the blob to store in its place — e.g. re-encoding an image, or stripping metadata. Runs after authentication and before the S3 write, so only the returned bytes are ever stored. The blob's type becomes the object's Content-Type, so change it when the format changes. Return the file unchanged to leave it alone. Throwing fails the upload.

    putOptions?: (
        data: { data?: object; type: string; userId: number },
    ) => PutOverrides

    Optional. Given { type, userId, data }, returns fields to set on the S3 put — CacheControl, ContentDisposition, Metadata and so on. A function rather than a static object so headers can differ per upload kind. See PutOverrides.