Sanity Library Reference Docs
    Preparing search index...

    Function defineMediaLibraryAssetFunction

    • Defines a function that is triggered by media library events.

      defineMediaLibraryAssetFunction({
      name: 'my-media-library-function',
      event: {
      on: ['create'],
      resource: {
      type: 'media-library',
      id: 'my-media-library-id',
      },
      },
      })

      Parameters

      • functionConfig: BlueprintMediaLibraryAssetFunctionConfig

        The configuration for the media library asset function

        Configuration for defining a media library asset function.

        • OptionaldisplayName?: string

          Human-readable display name for the function

        • Optionalenv?: Record<string, string>

          Environment variables provided to the function

        • event: BlueprintMediaLibraryFunctionResourceEvent

          Event configuration specifying when and how the function is triggered

        • Optionalmemory?: number

          Memory allocation in gigabytes

        • name: string
        • Optionalproject?: string

          The project ID of the project that contains your function.

          The project attribute must be defined if your blueprint is scoped to an organization.

        • OptionalrobotToken?: string

          Token provided during function invocation

        • Optionalruntime?: "node" | "nodejs22.x" | "nodejs24.x"

          The runtime environment for the function (currently only Node.js is supported)

          'nodejs24.x'
          
        • Optionalsrc?: string

          Path to the function source code

          functions/${name}

        • Optionaltimeout?: number

          Execution timeout in seconds

      Returns BlueprintMediaLibraryAssetFunctionResource

      The validated media library asset function resource