Socket
Socket
Sign inDemoInstall

@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

TypeScript definitions for multer


Version published
Weekly downloads
1.8M
decreased by-4.8%
Maintainers
1
Weekly downloads
 
Created

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

FAQs

Package last updated on 07 Jul 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc