Socket
Socket
Sign inDemoInstall

multer-media

Package Overview
Dependencies
36
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    multer-media

Multer Media files upload


Version published
Weekly downloads
44
increased by1000%
Maintainers
1
Install size
76.8 MB
Created
Weekly downloads
 

Readme

Source

Multer media

Installation

$ yarn add multer-media

Usage

  const upload = multer({
      storage: multerMedia({
        algorithm: 'md5',
        
        destination: (
          req: ExpressRequest,
          file: Express.Multer.File,
          callback: (error: Error | null, path: string) => void,
        ) => {
          callback(null, '/tmp/my-uploads');
        },
        
        filename: (
          req: ExpressRequest,
          file: Express.Multer.File,
          callback: (error: Error | null, path: string) => void,
        ) => {
          const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9)
          callback(null, file.fieldname + '-' + uniqueSuffix);
        },

        /**
         * A function that will be executed on start
         *
         * @param req The Express `Request` object.
         * @param file Object containing information about the processed file.
         * @param src Stream Readable
         */
        start?: (
          req: Request,
          file: Express.Multer.File,
          outStream?: stream.Writable,
          chunk?: any,
          encoding?: BufferEncoding,
        ) => {},

        /**
         * A function that will be executed on write events
         *
         * @param req The Express `Request` object.
         * @param file Object containing information about the processed file.
         * @param src Stream Readable
         */
        write?: (
          req: Request,
          file: Express.Multer.File,
          outStream?: stream.Writable,
          chunk?: any,
          encoding?: BufferEncoding,
        ) => {},

        /**
         * A function that will be executed on write events
         *
         * @param req The Express `Request` object.
         * @param file Object containing information about the processed file.
         * @param src Stream Readable
         */
        finish?: (
          req: Request,
          file: Express.Multer.File,
          outStream?: stream.Writable,
          chunk?: any,
          encoding?: BufferEncoding,
        ) => {},
      }),
  });

API

File information

Each file contains the following information:

KeyTypeDescription
fieldnamestringField name specified in the form
originalnamestringName of the file on the user's computer
encodingstringEncoding type of the file
mimetypestringMime type of the file
sizenumberSize of the file in bytes
destinationstringThe folder to which the file has been saved
filenamestringThe name of the file within the destination
pathstringThe full path to the uploaded file
hashstringHash with algorithm the file
mediaFfprobeDataMedia probe of this file, using ffmpeg-static

Keywords

FAQs

Last updated on 21 Aug 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc