Configurations

Multiple configuration options can be provided to the Media module to customize the behaviour of the Media module.

interface MediaOptions {
    prismaClient: InjectionToken;
    swagger: boolean;
    validation?: {
        maxSize?: number;
        allowedMimeTypes?: (string | RegExp)[];
        customValidators?: FileValidator[];
        validationExceptionFactory?: (error: string) => any;
    };
    storage?: AsyncStorageManagerModuleFactoryOptions;
    decorators?: (() => ClassDecorator)[];
    guards?: (CanActivate | Function)[];
    operationConfig?: MediaOperationsConfig;
}
  1. prismaClient [Required] The injection token that can be used to retrieve the Prisma client instance

  2. swagger [Required] Whether or not a swagger interface should be generated for the auto-generated controllers

  3. validation An object that contains multiple validation options

    1. maxSize: The maximum allowed size of the uploaded media. default unlimited

    2. allowedMimeType: An array of the allowed mime types arrow-up-right

    3. customValidators: an array of custom validators that will be used before uploading any media, see NestJs documentationarrow-up-right for more information on how to write custom validators

    4. validationExceptionFactory: factory function that will be used to construct the exception that will be returned to the user.

  4. storage configuration options for the StorageModule if it is not already globally provided, see Storage Configuration for more options

  5. Note: If you choose to use Local Storage for storing media files, there won't be a built-in way to serve these files directly. To make your media files accessible, you need to set up a Static Server such as:

    Make sure to configure your static server correctly to expose your media files for frontend consumption. 🚀

  6. decorators An array of factory functions of class decorators to be applied on the auto-generated controllers

  7. guards An array of NestJS guards to be applied on the auto-generated controllers

  8. operationConfig a custom decorators and guards to be used on specific operations

Last updated