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);
},
start?: (
req: Request,
file: Express.Multer.File,
outStream?: stream.Writable,
chunk?: any,
encoding?: BufferEncoding,
) => {},
write?: (
req: Request,
file: Express.Multer.File,
outStream?: stream.Writable,
chunk?: any,
encoding?: BufferEncoding,
) => {},
finish?: (
req: Request,
file: Express.Multer.File,
outStream?: stream.Writable,
chunk?: any,
encoding?: BufferEncoding,
) => {},
}),
});
API
File information
Each file contains the following information:
Key | Type | Description |
---|
fieldname | string | Field name specified in the form |
originalname | string | Name of the file on the user's computer |
encoding | string | Encoding type of the file |
mimetype | string | Mime type of the file |
size | number | Size of the file in bytes |
destination | string | The folder to which the file has been saved |
filename | string | The name of the file within the destination |
path | string | The full path to the uploaded file |
hash | string | Hash with algorithm the file |
media | FfprobeData | Media probe of this file, using ffmpeg-static |