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

parse-multipart-data

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-multipart-data

A javascript/nodejs multipart/form-data parser which operates on raw data.

  • 1.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is parse-multipart-data?

The parse-multipart-data npm package is used to parse multipart/form-data, which is commonly used for file uploads in web applications. It allows you to extract files and fields from multipart form data.

What are parse-multipart-data's main functionalities?

Parsing Multipart Data

This feature allows you to parse multipart form data. The code sample demonstrates how to parse a multipart body with a boundary string, extracting both a text field and a file.

const { parse } = require('parse-multipart-data');

const boundary = '----WebKitFormBoundary7MA4YWxkTrZu0gW';
const body = Buffer.from('--' + boundary + '\r\nContent-Disposition: form-data; name="field1"\r\n\r\nvalue1\r\n--' + boundary + '\r\nContent-Disposition: form-data; name="file1"; filename="example.txt"\r\nContent-Type: text/plain\r\n\r\nHello, World!\r\n--' + boundary + '--');

const parts = parse(body, boundary);
console.log(parts);

Extracting Files

This feature allows you to extract files from the parsed multipart data. The code sample demonstrates how to find and extract a file named 'example.txt' from the multipart body.

const { parse } = require('parse-multipart-data');

const boundary = '----WebKitFormBoundary7MA4YWxkTrZu0gW';
const body = Buffer.from('--' + boundary + '\r\nContent-Disposition: form-data; name="file1"; filename="example.txt"\r\nContent-Type: text/plain\r\n\r\nHello, World!\r\n--' + boundary + '--');

const parts = parse(body, boundary);
const file = parts.find(part => part.filename === 'example.txt');
console.log(file);

Extracting Fields

This feature allows you to extract fields from the parsed multipart data. The code sample demonstrates how to find and extract a field named 'field1' from the multipart body.

const { parse } = require('parse-multipart-data');

const boundary = '----WebKitFormBoundary7MA4YWxkTrZu0gW';
const body = Buffer.from('--' + boundary + '\r\nContent-Disposition: form-data; name="field1"\r\n\r\nvalue1\r\n--' + boundary + '--');

const parts = parse(body, boundary);
const field = parts.find(part => part.name === 'field1');
console.log(field);

Other packages similar to parse-multipart-data

Keywords

FAQs

Package last updated on 15 Sep 2022

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