Socket
Socket
Sign inDemoInstall

express-parse-multipart

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    express-parse-multipart

An Express.js middleware for parsing "multipart/form-data" content type


Version published
Weekly downloads
1.2K
decreased by-34.84%
Maintainers
1
Install size
8.37 kB
Created
Weekly downloads
 

Readme

Source

Description

Middleware parses request body with multipart/form-data content type and prepares an array of objects which represent every file which is sent in request. On the server side you will be able to get that array from req.formData property (see an example below). Every array item will contain data property which is a Buffer.

Using

  1. Make a simple Express.js server in index.js file:

    const app = require('express')();
    const parseMp = require('express-parse-multipart');
    
    app.post('/upload', parseMp, (req, res) => {
      console.log(req.formData);  // here is the target array of objects
      return res.send('Yay!');
    });
    
    app.listen(3000, () => console.log('Started on: http://localhost:3000'));
    
  2. Run it:

    node index.js
    
  3. Make a POST request using any tool you want and send any file (-s) on http://localhost:3000/upload route. Check console to see the parsed result.

Example of req.formData

[
  {
    "data": {
      "type": "Buffer",
      "data": [
        78,
        97,
        10
      ]
    },
    "name": "file1",
    "filename": "csv_test.csv",
    "type": "text/csv"
  },
  {
    "data": {
      "type": "Buffer",
      "data": [
        137,
        80,
        130
      ]
    },
    "filename": "img_test.png",
    "type": "image/png"
  },
  {
    "data": {
      "type": "Buffer",
      "data": [
        74,
        68,
        69
      ]
    },
    "name": "text1"
  }
]

Keywords

FAQs

Last updated on 15 Aug 2020

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