New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

form-data-body

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

form-data-body

A tiny, dependency-free node module for generating a form's multipart/form-data body for a POST request.

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
118
decreased by-81.36%
Maintainers
1
Weekly downloads
 
Created
Source

form-data-body

npm package version Travis build status npm package downloads code style license

A tiny, dependency-free node module for generating a form's multipart/form-data body for a POST request.

This is meant to be a simple, no frills module for generating a string to send as the body for a POST request simulating a form submission. If you need something with more bells and whistles, check out the form-data module.

Installation

npm install --save form-data-body

Usage

const formDataBody = require('form-data-body')

// Specify form fields
const fields = {
  name: 'My test post',
  description: 'This is just a test post',
  items: ['First Item', 'Second Item'],

  // Files should be an object with the name, type, and data set to strings
  image: {
    name: 'hello.jpg',
    type: 'image/jpeg',
    data: binaryImageData
  }
}

const boundary = formDataBody.generateBoundary()
const header = {
  'Content-Type': `multipart/form-data; boundary=${boundary}`
}
const body = formDataBody(fields, boundary)

Example Response

----------------------------071517909670537006900435
Content-Disposition: form-data; name="name"

My test post
----------------------------071517909670537006900435
Content-Disposition: form-data; name="description"

This is just a test post
----------------------------071517909670537006900435
Content-Disposition: form-data; name="items[]"

First Item
----------------------------071517909670537006900435
Content-Disposition: form-data; name="items[]"

Second Item
----------------------------071517909670537006900435
Content-Disposition: form-data; name="image"; filename="hello.jpg"
Content-Type: image/jpeg

[BINARY IMAGE DATA]
----------------------------071517909670537006900435--

License

MIT. See the LICENSE file for more info.

Keywords

FAQs

Package last updated on 23 Feb 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