@types/multer
- Version 1.4.12
- Published
- 16.5 kB
- 1 dependency
- MIT license
Install
npm i @types/multer
yarn add @types/multer
pnpm add @types/multer
Overview
TypeScript definitions for multer
Index
Functions
Classes
Interfaces
Type Aliases
Namespaces
Functions
function diskStorage
diskStorage: (options: DiskStorageOptions) => StorageEngine;
Returns a
StorageEngine
implementation configured to store files on the local file system.A string or function may be specified to determine the destination directory, and a function to determine filenames. If no options are set, files will be stored in the system's temporary directory with random 32 character filenames.
function memoryStorage
memoryStorage: () => StorageEngine;
Returns a
StorageEngine
implementation configured to store files in memory asBuffer
objects.
function multer
multer: typeof multer;
Returns a Multer instance that provides several methods for generating middleware that process files uploaded in
multipart/form-data
format.The
StorageEngine
specified instorage
will be used to store files. Ifstorage
is not set anddest
is, files will be stored indest
on the local file system with random names. If neither are set, files will be stored in memory.In addition to files, all generated middleware process all text fields in the request. For each non-file field, the
Request.body
object will be populated with an entry mapping the field name to its string value, or array of string values if multiple fields share the same name.
Classes
class MulterError
class MulterError extends Error {}
constructor
constructor(code: ErrorCode, field?: string);
property code
code: ErrorCode;
Identifying error code.
property field
field?: string;
Name of the multipart form field associated with this error.
property message
message: string;
Descriptive error message.
property name
name: string;
Name of the MulterError constructor.
Interfaces
interface DiskStorageOptions
interface DiskStorageOptions {}
property destination
destination?: | string | (( req: Request, file: Express.Multer.File, callback: (error: Error | null, destination: string) => void ) => void) | undefined;
A string or function that determines the destination path for uploaded files. If a string is passed and the directory does not exist, Multer attempts to create it recursively. If neither a string or a function is passed, the destination defaults to
os.tmpdir()
.Parameter req
The Express
Request
object.Parameter file
Object containing information about the processed file.
Parameter callback
Callback to determine the destination path.
method filename
filename: ( req: Request, file: Express.Multer.File, callback: (error: Error | null, filename: string) => void) => void;
A function that determines the name of the uploaded file. If nothing is passed, Multer will generate a 32 character pseudorandom hex string with no extension.
Parameter req
The Express
Request
object.Parameter file
Object containing information about the processed file.
Parameter callback
Callback to determine the name of the uploaded file.
interface Field
interface Field {}
An object describing a field name and the maximum number of files with that field name to accept.
interface FileFilterCallback
interface FileFilterCallback {}
a function to control which files should be uploaded and which should be skipped pass a boolean to indicate if the file should be accepted pass an error if something goes wrong
call signature
(error: Error): void;
call signature
(error: null, acceptFile: boolean): void;
interface Multer
interface Multer {}
method any
any: () => RequestHandler;
Returns middleware that processes all files contained in the multipart request.
The
Request
object will be populated with afiles
array containing an information object for each processed file.
method array
array: (fieldName: string, maxCount?: number) => RequestHandler;
Returns middleware that processes multiple files sharing the same field name.
The
Request
object will be populated with afiles
array containing an information object for each processed file.Parameter fieldName
Shared name of the multipart form fields to process.
Parameter maxCount
Optional. Maximum number of files to process. (default: Infinity)
Throws
MulterError('LIMIT_UNEXPECTED_FILE')
if more thanmaxCount
files are associated withfieldName
method fields
fields: (fields: readonly Field[]) => RequestHandler;
Returns middleware that processes multiple files associated with the given form fields.
The
Request
object will be populated with afiles
object which maps each field name to an array of the associated file information objects.Parameter fields
Array of
Field
objects describing multipart form fields to process.Throws
MulterError('LIMIT_UNEXPECTED_FILE')
if more thanmaxCount
files are associated withfieldName
for any field.
method none
none: () => RequestHandler;
Returns middleware that accepts only non-file multipart form fields.
Throws
MulterError('LIMIT_UNEXPECTED_FILE')
if any file is encountered.
method single
single: (fieldName: string) => RequestHandler;
Returns middleware that processes a single file associated with the given form field.
The
Request
object will be populated with afile
object containing information about the processed file.Parameter fieldName
Name of the multipart form field to process.
interface Options
interface Options {}
Options for initializing a Multer instance.
property dest
dest?: string | undefined;
The destination directory for uploaded files. If
storage
is not set anddest
is, Multer will create aDiskStorage
instance configured to store files atdest
with random filenames.Ignored if
storage
is set.
property limits
limits?: | { /** Maximum size of each form field name in bytes. (Default: 100) */ fieldNameSize?: number | undefined; /** Maximum size of each form field value in bytes. (Default: 1048576) */ fieldSize?: number | undefined; /** Maximum number of non-file form fields. (Default: Infinity) */ fields?: number | undefined; /** Maximum size of each file in bytes. (Default: Infinity) */ fileSize?: number | undefined; /** Maximum number of file fields. (Default: Infinity) */ files?: number | undefined; /** Maximum number of parts (non-file fields + files). (Default: Infinity) */ parts?: number | undefined; /** Maximum number of headers. (Default: 2000) */ headerPairs?: number | undefined; } | undefined;
An object specifying various limits on incoming data. This object is passed to Busboy directly, and the details of properties can be found at https://github.com/mscdex/busboy#busboy-methods.
property preservePath
preservePath?: boolean | undefined;
Preserve the full path of the original filename rather than the basename. (Default: false)
property storage
storage?: StorageEngine | undefined;
A
StorageEngine
responsible for processing files uploaded via Multer. Takes precedence overdest
.
method fileFilter
fileFilter: ( req: Request, file: Express.Multer.File, callback: FileFilterCallback) => void;
Optional function to control which files are uploaded. This is called for every file that is processed.
Parameter req
The Express
Request
object.Parameter file
Object containing information about the processed file.
Parameter callback
a function to control which files should be uploaded and which should be skipped.
interface StorageEngine
interface StorageEngine {}
Implementations of this interface are responsible for storing files encountered by Multer and returning information on how to access them once stored. Implementations must also provide a method for removing files in the event that an error occurs.
Type Aliases
type ErrorCode
type ErrorCode = | 'LIMIT_PART_COUNT' | 'LIMIT_FILE_SIZE' | 'LIMIT_FILE_COUNT' | 'LIMIT_FIELD_KEY' | 'LIMIT_FIELD_VALUE' | 'LIMIT_FIELD_COUNT' | 'LIMIT_UNEXPECTED_FILE';
Namespaces
namespace global
namespace global {}
namespace global.Express
namespace global.Express {}
interface Request
interface Request {}
namespace global.Express.Multer
namespace global.Express.Multer {}
interface File
interface File {}
Object containing file metadata and access information.
property buffer
buffer: Buffer;
MemoryStorage
only: A Buffer containing the entire file.
property destination
destination: string;
DiskStorage
only: Directory to which this file has been uploaded.
property encoding
encoding: string;
Value of the
Content-Transfer-Encoding
header for this file.See Also
RFC 7578, Section 4.7
Deprecated
since July 2015
property fieldname
fieldname: string;
Name of the form field associated with this file.
property filename
filename: string;
DiskStorage
only: Name of this file withindestination
.
property mimetype
mimetype: string;
Value of the
Content-Type
header for this file.
property originalname
originalname: string;
Name of the file on the uploader's computer.
property path
path: string;
DiskStorage
only: Full path to the uploaded file.
property size
size: number;
Size of the file in bytes.
property stream
stream: Readable;
A readable stream of this file. Only available to the
_handleFile
callback for customStorageEngine
s.
Package Files (1)
Dependencies (1)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/multer
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/multer)
- HTML<a href="https://www.jsdocs.io/package/@types/multer"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3295 ms. - Missing or incorrect documentation? Open an issue for this package.