Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/multer

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/multer - npm Package Compare versions

Comparing version 1.3.10 to 1.4.0

352

multer/index.d.ts

@@ -1,2 +0,2 @@

// Type definitions for multer 1.3
// Type definitions for multer 1.4
// Project: https://github.com/expressjs/multer

@@ -9,120 +9,298 @@ // Definitions by: jt000 <https://github.com/jt000>

// Pierre Tchuente <https://github.com/PierreTchuente>
// Oliver Emery <https://github.com/thrymgjol>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
// TypeScript Version: 2.8
import * as express from 'express';
import { Request, RequestHandler } from 'express';
import { Readable } from 'stream';
declare global {
namespace Express {
namespace Multer {
/** Object containing file metadata and access information. */
interface File {
/** Name of the form field associated with this file. */
fieldname: string;
/** Name of the file on the uploader's computer. */
originalname: string;
/**
* Value of the `Content-Transfer-Encoding` header for this file.
* @deprecated since July 2015
* @see RFC 7578, Section 4.7
*/
encoding: string;
/** Value of the `Content-Type` header for this file. */
mimetype: string;
/** Size of the file in bytes. */
size: number;
/** `DiskStorage` Directory to which this file has been uploaded. */
destination: string;
/** `DiskStorage` Name of this file within `destination`. */
filename: string;
/** `DiskStorage` Full path to the uploaded file. */
path: string;
/** `MemoryStorage` A Buffer containing the entire file. */
buffer: Buffer;
/** A readable stream of this file. */
stream: Readable;
}
}
interface Request {
/** `Multer.File` object populated by `single()` middleware. */
file: Multer.File;
/**
* Array or dictionary of `Multer.File` object populated by `array()`,
* `fields()`, and `any()` middleware.
*/
files: {
[fieldname: string]: Multer.File[];
} | Multer.File[];
}
}
}
declare class Multer {
/**
* Returns middleware that processes a single file associated with the
* given form field.
*
* The `Request` object will be populated with a `file` object containing
* information about the processed file.
*
* @param fieldName Name of the multipart form field to process.
*/
single(fieldName: string): RequestHandler;
/**
* Returns middleware that processes multiple files sharing the same field
* name.
*
* The `Request` object will be populated with a `files` array containing
* an information object for each processed file.
*
* @param fieldName Shared name of the multipart form fields to process.
* @param maxCount Optional. Maximum number of files to process. (default: Infinity)
* @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if more than `maxCount` files are associated with `fieldName`
*/
array(fieldName: string, maxCount?: number): RequestHandler;
/**
* Returns middleware that processes multiple files associated with the
* given form fields.
*
* The `Request` object will be populated with a `files` object which
* maps each field name to an array of the associated file information
* objects.
*
* @param fields Array of `Field` objects describing multipart form fields to process.
* @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if more than `maxCount` files are associated with `fieldName` for any field.
*/
fields(fields: ReadonlyArray<multer.Field>): RequestHandler;
/**
* Returns middleware that processes all files contained in the multipart
* request.
*
* The `Request` object will be populated with a `files` array containing
* an information object for each processed file.
*/
any(): RequestHandler;
/**
* Returns middleware that accepts only non-file multipart form fields.
*
* @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if any file is encountered.
*/
none(): RequestHandler;
}
/**
* Returns a Multer instance that provides several methods for generating
* middleware that process files uploaded in `multipart/form-data` format.
*
* The `StorageEngine` specified in `storage` will be used to store files. If
* `storage` is not set and `dest` is, files will be stored in `dest` 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.
*/
declare function multer(options?: multer.Options): Multer;
declare namespace multer {
interface Field {
/** The field name. */
/**
* 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 diskStorage(options: DiskStorageOptions): StorageEngine;
/**
* Returns a `StorageEngine` implementation configured to store files in
* memory as `Buffer` objects.
*/
function memoryStorage(): StorageEngine;
type ErrorCode =
| 'LIMIT_PART_COUNT'
| 'LIMIT_FILE_SIZE'
| 'LIMIT_FILE_COUNT'
| 'LIMIT_FIELD_KEY'
| 'LIMIT_FIELD_VALUE'
| 'LIMIT_FIELD_COUNT'
| 'LIMIT_UNEXPECTED_FILE';
class MulterError extends Error {
constructor(code: ErrorCode, field?: string);
/** Name of the MulterError constructor. */
name: string;
/** Optional maximum number of files per field to accept. */
maxCount?: number;
/** Identifying error code. */
code: ErrorCode;
/** Descriptive error message. */
message: string;
/** Name of the multipart form field associated with this error. */
field?: string;
}
/** Options for initializing a Multer instance. */
interface Options {
/** The destination directory for the uploaded files. */
dest?: string;
/** The storage engine to use for uploaded files. */
/**
* A `StorageEngine` responsible for processing files uploaded via Multer.
* Takes precedence over `dest`.
*/
storage?: StorageEngine;
/**
* An object specifying the size limits of the following optional properties. This object is passed to busboy
* directly, and the details of properties can be found on https://github.com/mscdex/busboy#busboy-methods
* The destination directory for uploaded files. If `storage` is not set
* and `dest` is, Multer will create a `DiskStorage` instance configured
* to store files at `dest` with random filenames.
*
* Ignored if `storage` is set.
*/
dest?: string;
/**
* 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.
*/
limits?: {
/** Max field name size (Default: 100 bytes) */
/** Maximum size of each form field name in bytes. (Default: 100) */
fieldNameSize?: number;
/** Max field value size (Default: 1MB) */
/** Maximum size of each form field value in bytes. (Default: 1048576) */
fieldSize?: number;
/** Max number of non- file fields (Default: Infinity) */
/** Maximum number of non-file form fields. (Default: Infinity) */
fields?: number;
/** For multipart forms, the max file size (in bytes)(Default: Infinity) */
/** Maximum size of each file in bytes. (Default: Infinity) */
fileSize?: number;
/** For multipart forms, the max number of file fields (Default: Infinity) */
/** Maximum number of file fields. (Default: Infinity) */
files?: number;
/** For multipart forms, the max number of parts (fields + files)(Default: Infinity) */
/** Maximum number of parts (non-file fields + files). (Default: Infinity) */
parts?: number;
/** For multipart forms, the max number of header key=> value pairs to parse Default: 2000(same as node's http). */
/** Maximum number of headers. (Default: 2000) */
headerPairs?: number;
};
/** Keep the full path of files instead of just the base name (Default: false) */
/** Preserve the full path of the original filename rather than the basename. (Default: false) */
preservePath?: boolean;
/** A function to control which files to upload and which to skip. */
fileFilter?(req: Express.Request, file: Express.Multer.File, callback: (error: Error | null, acceptFile: boolean) => void): void;
/**
* Optional function to control which files are uploaded. This is called
* for every file that is processed.
*
* @param req The Express `Request` object.
* @param file Object containing information about the processed file.
* @param callback Callback to accept or deny the file.
*/
fileFilter?(
req: Request,
file: Express.Multer.File,
callback: (error: Error | null, acceptFile: boolean) => void
): void;
}
/**
* 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.
*/
interface StorageEngine {
_handleFile(req: express.Request, file: Express.Multer.File, callback: (error?: any, info?: Partial<Express.Multer.File>) => void): void;
_removeFile(req: express.Request, file: Express.Multer.File, callback: (error: Error) => void): void;
/**
* Store the file described by `file`, then invoke the callback with
* information about the stored file.
*
* File contents are available as a stream via `file.stream`. Information
* passed to the callback will be merged with `file` for subsequent
* middleware.
*
* @param req The Express `Request` object.
* @param file Object with `stream`, `fieldname`, `originalname`, `encoding`, and `mimetype` defined.
* @param callback Callback to specify file information.
*/
_handleFile(
req: Request,
file: Express.Multer.File,
callback: (error?: any, info?: Partial<Express.Multer.File>) => void
): void;
/**
* Remove the file described by `file`, then invoke the callback with.
*
* `file` contains all the properties available to `_handleFile`, as
* well as those returned by `_handleFile`.
*
* @param req The Express `Request` object.
* @param file Object containing information about the processed file.
* @param callback Callback to indicate completion.
*/
_removeFile(
req: Request,
file: Express.Multer.File,
callback: (error: Error) => void
): void;
}
interface DiskStorageOptions {
/** A function used to determine within which folder the uploaded files should be stored. Defaults to the system's default temporary directory. */
destination?: string | ((req: Express.Request, file: Express.Multer.File, callback: (error: Error | null, destination: string) => void) => void);
/** A function used to determine what the file should be named inside the folder. Defaults to a random name with no file extension. */
filename?(req: Express.Request, file: Express.Multer.File, callback: (error: Error | null, filename: string) => void): void;
/**
* 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()`.
*
* @param req The Express `Request` object.
* @param file Object containing information about the processed file.
* @param callback Callback to determine the destination path.
*/
destination?: string | ((
req: Request,
file: Express.Multer.File,
callback: (error: Error | null, destination: 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.
*
* @param req The Express `Request` object.
* @param file Object containing information about the processed file.
* @param callback Callback to determine the name of the uploaded file.
*/
filename?(
req: Request,
file: Express.Multer.File,
callback: (error: Error | null, filename: string) => void
): void;
}
interface Instance {
/** In case you need to handle a text-only multipart form, you can use any of the multer methods (.single(), .array(), fields()), req.body contains the text fields */
/** Accept a single file with the name fieldName. The single file will be stored in req.file. */
single(fieldName?: string): express.RequestHandler;
/** Accept an array of files, all with the name fieldName. Optionally error out if more than maxCount files are uploaded. The array of files will be stored in req.files. */
array(fieldName: string, maxCount?: number): express.RequestHandler;
/** Accept a mix of files, specified by fields. An object with arrays of files will be stored in req.files. */
fields(fields: Field[]): express.RequestHandler;
/** Accepts all files that comes over the wire. An array of files will be stored in req.files. */
any(): express.RequestHandler;
/** Accept only text fields. If any file upload is made, error with code “LIMIT_UNEXPECTED_FILE” will be issued. This is the same as doing upload.fields([]). */
none(): express.RequestHandler;
/**
* An object describing a field name and the maximum number of files with
* that field name to accept.
*/
interface Field {
/** The field name. */
name: string;
/** Optional maximum number of files per field to accept. (Default: Infinity) */
maxCount?: number;
}
}
interface Multer {
(options?: multer.Options): multer.Instance;
/* The disk storage engine gives you full control on storing files to disk. */
diskStorage(options: multer.DiskStorageOptions): multer.StorageEngine;
/* The memory storage engine stores the files in memory as Buffer objects. */
memoryStorage(): multer.StorageEngine;
}
declare const multer: Multer;
export = multer;
declare global {
namespace Express {
interface Request {
file: Multer.File;
files: {
[fieldname: string]: Multer.File[];
} | Multer.File[];
}
namespace Multer {
interface File {
/** Field name specified in the form */
fieldname: string;
/** Name of the file on the user's computer */
originalname: string;
/** Encoding type of the file */
encoding: string;
/** Mime type of the file */
mimetype: string;
/** Size of the file in bytes */
size: number;
/** The folder to which the file has been saved (DiskStorage) */
destination: string;
/** The url where to get the uploaded file (aws S3 for example) */
location: string;
/** The name of the file within the destination (DiskStorage) */
filename: string;
/** Location of the uploaded file (DiskStorage) */
path: string;
/** A Buffer of the entire file (MemoryStorage) */
buffer: Buffer;
}
}
}
}
{
"name": "@types/multer",
"version": "1.3.10",
"version": "1.4.0",
"description": "TypeScript definitions for multer",

@@ -35,6 +35,11 @@ "license": "MIT",

"githubUsername": "PierreTchuente"
},
{
"name": "Oliver Emery",
"url": "https://github.com/thrymgjol",
"githubUsername": "thrymgjol"
}
],
"main": "",
"types": "index",
"types": "index.d.ts",
"repository": {

@@ -49,4 +54,4 @@ "type": "git",

},
"typesPublisherContentHash": "39d3fe14ef10f272311215dd61734a2473e1cd5a4c82d4ee00571742dfbfacfb",
"typeScriptVersion": "2.3"
"typesPublisherContentHash": "4fdef18195bb50db06c46659e9e36ea0cc8a48f795296ebe25249431a9fd4fcb",
"typeScriptVersion": "2.8"
}

@@ -8,10 +8,10 @@ # Installation

# Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/multer
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/multer.
Additional Details
* Last updated: Wed, 25 Sep 2019 18:34:17 GMT
* Dependencies: @types/express
### Additional Details
* Last updated: Mon, 27 Jan 2020 22:09:38 GMT
* Dependencies: [@types/express](https://npmjs.com/package/@types/express)
* Global values: none
# Credits
These definitions were written by jt000 <https://github.com/jt000>, vilicvane <https://vilic.github.io/>, David Broder-Rodgers <https://github.com/DavidBR-SW>, Michael Ledin <https://github.com/mxl>, HyunSeob Lee <https://github.com/hyunseob>, and Pierre Tchuente <https://github.com/PierreTchuente>.
These definitions were written by jt000 (https://github.com/jt000), vilicvane (https://vilic.github.io/), David Broder-Rodgers (https://github.com/DavidBR-SW), Michael Ledin (https://github.com/mxl), HyunSeob Lee (https://github.com/hyunseob), Pierre Tchuente (https://github.com/PierreTchuente), and Oliver Emery (https://github.com/thrymgjol).
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc