Options
All
  • Public
  • Public/Protected
  • All
Menu

express-multipart - v1.0.6

Index

Type aliases

MultipartFile

MultipartFile: { destination: string; encoding: string; extension: string; mime: string; name: string; originalName: string; path: string }

Type declaration

  • destination: string

    Path to the storage directory.

  • encoding: string

    File encoding.

  • extension: string

    File extension.

  • mime: string

    Mime type (based on the file extension).

  • name: string

    Name of the file that was persisted on a disk.

  • originalName: string

    Name of the file that was received in the form-data request.

  • path: string

    Full path to the persisted file.

MultipartMiddleware

MultipartMiddleware: (req: Request, res: Response, next: NextFunction) => void

Type declaration

    • (req: Request, res: Response, next: NextFunction): void
    • Parameters

      • req: Request
      • res: Response
      • next: NextFunction

      Returns void

MultipartOptions

MultipartOptions: { acceptedTypes?: string[]; destination?: string; fileName?: (originalName: string, mime: string) => string; maxFieldNameSize?: number; maxFieldSize?: number; maxSize?: number; onInvalidMagic?: (file: NodeJS.ReadableStream, contentMime: string, binaryMime?: string) => boolean; preserveExtensions?: boolean; verifyMagic?: boolean }

Type declaration

  • Optional acceptedTypes?: string[]

    Whitelisted mime types. (All if undefined)

    Default: all

  • Optional destination?: string

    A destination where files will be saved on a disk.

    Default: ./

  • Optional fileName?: (originalName: string, mime: string) => string

    The result of this function will work as a new file name persisted on a disk.

    Default: random hex string

      • (originalName: string, mime: string): string
      • Parameters

        • originalName: string
        • mime: string

        Returns string

  • Optional maxFieldNameSize?: number

    Max size of a field name in bytes.

    Default: 100 (100 B)

  • Optional maxFieldSize?: number

    Max size of a field in bytes.

    Default: 1048576 (1 MB)

  • Optional maxSize?: number

    Max size of a single file in bytes.

    Default: 8388608 (8 MB)

  • Optional onInvalidMagic?: (file: NodeJS.ReadableStream, contentMime: string, binaryMime?: string) => boolean

    This function will be executed if magic bytes verification couldn't be successfully performed. See verifyMagic for more information.

    If the function returns false, then the file will be rejected, otherwise Content-Type will be used.

      • (file: NodeJS.ReadableStream, contentMime: string, binaryMime?: string): boolean
      • Parameters

        • file: NodeJS.ReadableStream
        • contentMime: string
        • Optional binaryMime: string

        Returns boolean

  • Optional preserveExtensions?: boolean

    If true, extensions will be preserved in the file name.

    Default: false

    Warning: Preserving extensions can possibly be dangerous for security reasons, should always be used with verifyMagic set to true.

  • Optional verifyMagic?: boolean

    If true, magic bytes will be verified to check if the binary data of the file is correct.

    Default: false

    • If the file is not represented in a known (or accepted) binary format, then onInvalidMagic will be ran.
    • If the file binary data does not match request's Content-Type, then onInvalidMagic will be ran.
    • If any of the above conditions is met and onInvalidMagic is not declared, then the file will be rejected.

Functions

Const default

  • Constructor for the Multipart

    import multipart from "express-multipart";
    
    const mp = multipart();
    

    Parameters

    • Optional options: MultipartOptions

      Global multipart options that will be applied for all multipart requests.

    Returns Multipart

    New Multipart instance with specified option parameters (if there are any).

Const multipart

  • Constructor for the Multipart

    import multipart from "express-multipart";
    
    const mp = multipart();
    

    Parameters

    • Optional options: MultipartOptions

      Global multipart options that will be applied for all multipart requests.

    Returns Multipart

    New Multipart instance with specified option parameters (if there are any).

Generated using TypeDoc