Socket
Socket
Sign inDemoInstall

@types/multer

Package Overview
Dependencies
12
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @types/multer

TypeScript definitions for multer


Version published
Weekly downloads
1.3M
decreased by-18.71%
Maintainers
1
Install size
3.93 MB
Created
Weekly downloads
 

Package description

What is @types/multer?

The @types/multer package provides TypeScript type definitions for Multer, a node.js middleware for handling multipart/form-data, primarily used for uploading files. It allows developers to use Multer in TypeScript projects with type checking, enabling better development experience and error handling.

What are @types/multer's main functionalities?

File Upload

This feature allows for the uploading of files. The code sample demonstrates how to set up a simple file upload endpoint using Express and Multer, where files are saved to the 'uploads/' directory.

import express from 'express';
import multer from 'multer';

const upload = multer({ dest: 'uploads/' });
const app = express();

app.post('/upload', upload.single('file'), function (req, res) {
  console.log(req.file);
  res.send('File uploaded successfully.');
});

Multiple Files Upload

This feature supports the uploading of multiple files in a single request. The code sample shows how to configure an endpoint to accept a maximum of 5 files using the `upload.array` method.

import express from 'express';
import multer from 'multer';

const upload = multer({ dest: 'uploads/' });
const app = express();

app.post('/upload', upload.array('files', 5), function (req, res) {
  console.log(req.files);
  res.send('Files uploaded successfully.');
});

File Filtering

This feature allows for filtering files based on specific criteria, such as file type. The code sample demonstrates how to accept only JPEG files using a custom file filter.

import express from 'express';
import multer from 'multer';

const fileFilter = (req, file, cb) => {
  if (file.mimetype === 'image/jpeg') {
    cb(null, true);
  } else {
    cb(new Error('Only JPEG files are allowed!'), false);
  }
};

const upload = multer({ dest: 'uploads/', fileFilter });
const app = express();

app.post('/upload', upload.single('file'), function (req, res) {
  res.send('File uploaded successfully.');
});

Other packages similar to @types/multer

Readme

Source

Installation

npm install --save @types/multer

Summary

This package contains type definitions for multer (https://github.com/expressjs/multer).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/multer.

Additional Details

  • Last updated: Mon, 20 Nov 2023 23:36:24 GMT
  • Dependencies: @types/express

Credits

These definitions were written by jt000, vilicvane, David Broder-Rodgers, Michael Ledin, HyunSeob Lee, Pierre Tchuente, Oliver Emery, and Piotr Błażejewicz.

FAQs

Last updated on 21 Nov 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