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

request-multipart

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request-multipart - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

multipart.js

14

lib/formdata.js

@@ -8,3 +8,3 @@

var contentType = (body, options = {}) =>
options.contentType ? options.contentType :
options.type ? options.type :
// fs.ReadStream

@@ -14,3 +14,3 @@ body.path ? mime.lookup(body.path) :

body.hasOwnProperty('httpVersion') ? body.headers['content-type'] :
options.filename ? mime.lookup(options.filename) :
options.name ? mime.lookup(options.name) :
typeof body === 'object' ? 'application/octet-stream' :

@@ -22,4 +22,4 @@ typeof body === 'string' ? 'text/plain' : ''

// options || fs.ReadStream
var filename = path.basename(options.filename || body.path || '')
return filename ? `; filename="${path.basename(filename)}"` : ''
var name = path.basename(options.name || body.path || '')
return name ? `; filename="${path.basename(name)}"` : ''
}

@@ -32,6 +32,6 @@

.map(({name, body}) =>
body.options ? {name, body: body.value, options: body.options} : {name, body})
body.options ? {name, body: body.body, options: body.options} : {name, body})
.map(({name, body, options}) => (
(body instanceof stream.Stream && options && options.knownLength)
? body._knownLength = options.knownLength : null,
(body instanceof stream.Stream && options && options.length)
? body._knownLength = options.length : null,
{name, body, options}

@@ -38,0 +38,0 @@ ))

@@ -27,7 +27,7 @@

body.push(bl(preamble + headers + '\r\n\r\n'))
body.push(isstream(part.body) ? part.body : bl(part.body))
body.push(bl('\r\n'))
body.push(preamble + headers + '\r\n\r\n')
body.push(part.body)
body.push('\r\n')
})
body.push(bl(`--${boundary}--`))
body.push(`--${boundary}--`)

@@ -38,6 +38,8 @@ // if (options.postambleCRLF) {

var stream = new multistream(body)
stream._items = body // content-length
var arr = body.map((part) => isstream(part) ? part : bl(part))
var stream = new multistream(arr)
stream._items = arr // content-length
stream._raw = body // request-logs
return stream
}
{
"name": "request-multipart",
"version": "0.1.0",
"description": "Multipart Body Stream",
"version": "1.0.0",
"description": "Multipart body support for request-compose",
"keywords": [
"request",
"compose",
"http",
"multipart",

@@ -17,21 +20,22 @@ "form-data"

"dependencies": {
"bl": "^4.0.0",
"bl": "^4.0.3",
"isstream": "^0.1.2",
"mime-types": "^2.1.18",
"multistream": "^4.0.0",
"uuid": "^3.2.1"
"mime-types": "^2.1.28",
"multistream": "^4.0.1",
"uuid": "^8.3.2"
},
"devDependencies": {
"coveralls": "^3.0.0",
"coveralls": "^3.0.11",
"formidable": "^1.2.1",
"istanbul": "1.1.0-alpha.1",
"mocha": "^5.1.1",
"request-compose": "^1.2.2",
"request-logs": "^1.0.3"
"mocha": "^7.1.1",
"nyc": "^15.0.1",
"request-compose": "^2.1.0",
"request-logs": "^2.1.3"
},
"bin": {},
"main": "./mw.js",
"main": "./multipart.js",
"type": "commonjs",
"files": [
"lib/",
"mw.js",
"multipart.js",
"LICENSE",

@@ -43,4 +47,4 @@ "README.md",

"test": "npm run test:ci",
"test:ci": "mocha test/ --recursive",
"test:cov": "istanbul cover _mocha -- --recursive"
"test:ci": "npx mocha --recursive",
"test:cov": "npx nyc --reporter=lcov --reporter=text-summary mocha -- --recursive"
},

@@ -47,0 +51,0 @@ "engines": {

@@ -6,17 +6,20 @@

[multipart/form-data][form-data] and [multipart/related][related] support for [request-compose]
> _Multipart body support for **[request-compose]**_
```js
var compose = require('request-compose')
compose.Request.multipart = require('request-multipart')
var fs = require('fs')
var request = require('request-compose').extend({
Request: {multipart: require('request-multipart')}
}).client
;(async () => {
try {
var {body} = await compose.client({
var {res, body} = await request({
method: 'POST',
url: 'https://slack.com/api/files.upload',
qs: {title: 'My Awesome Cat!'},
headers: {authorization: 'Bearer [ACCESS TOKEN]'},
multipart: {file: fs.readFileSync('cat.png')}
headers: {
authorization: 'Bearer [ACCESS TOKEN]'
},
multipart: {
file: require('fs').createReadStream('cat.png')
}
})

@@ -31,51 +34,144 @@ console.log(body)

# Table of Contents
# multipart/form-data
- [multipart/**form-data**](#multipart-form-data)
- [multipart/**related**](#multipart-related)
- [**examples**][examples]
```js
multipart: {
key: 'value' // String, Buffer or Stream
}
```
```js
multipart: {
status: 'Hello',
'media[]': fs.createReadStream('cat.png')
}
```
# multipart/form-data
```
--88b7fcd3-7776-4087-8b09-5b0f5c8af069
Content-Disposition: form-data; name="status"
Content-Type: text/plain
*value* can be `String`, `Buffer` or `Stream`
Hello
--88b7fcd3-7776-4087-8b09-5b0f5c8af069
Content-Disposition: form-data; name="media[]"; filename="cat.png"
Content-Type: image/png
...stream...
```
### Options
> Most servers expect the `filename` key to be set inside the `Content-Disposition` and a correct MIME type to be specified as `Content-Type`. When reading a file as `Buffer` request-multipart cannot determine those values.
```js
multipart: {
key: 'value'
key: {
body: 'value', // String, Buffer or Stream
options: {name: '', type: '', length: 0}
}
}
```
```js
multipart: {
file: {
body: fs.readFileSync('cat.png'),
options: {name: 'cat.png', type: 'image/png'}
}
}
```
```
--77f9de0f-8905-4b63-9ca9-ad1ff9827053
Content-Disposition: form-data; name="file"; filename="cat.png"
Content-Type: image/png
...buffer...
```
### List
```js
multipart: {
key: [
'value',
'value',
'value', // String, Buffer or Stream
'value', // String, Buffer or Stream
]
}
```
```js
multipart: {
key: {
value: 'value',
options: {filename: '', contentType: '', knownLength: 0}
}
attachment: [
fs.createReadStream('cat.png'),
fs.createReadStream('beep.mp3')
]
}
```
```
--21cd47c7-379b-43f3-8e5e-d95c36653abf
Content-Disposition: form-data; name="attachment"; filename="cat.png"
Content-Type: image/png
...stream...
--21cd47c7-379b-43f3-8e5e-d95c36653abf
Content-Disposition: form-data; name="attachment"; filename="beep.mp3"
Content-Type: audio/mpeg
...stream...
```
# multipart/related
*body* can be `String`, `Buffer` or `Stream`
```js
multipart: [
{
key: 'value',
body: 'value' // String, Buffer or Stream
},
{
key: 'value',
body: 'value' // String, Buffer or Stream
}
]
```
```js
multipart: [
{key: 'value', body: 'body'},
{key: 'value', body: 'body'},
{
'Content-Type': 'application/json',
body: JSON.stringify({name: 'cat.png'})
},
{
'Content-Type': 'image/png',
body: fs.createReadStream('cat.png')
}
]
```
```
--f3386c29-f73f-423f-b80e-9dac2801893b
Content-Type: application/json
{"name":"cat.png"}
--f3386c29-f73f-423f-b80e-9dac2801893b
Content-Type: image/png
...stream...
```
# [examples]
```bash
DEBUG=req,res,body,json node examples/multipart.js slack
```
[npm-version]: https://img.shields.io/npm/v/request-multipart.svg?style=flat-square (NPM Package Version)
[travis-ci]: https://img.shields.io/travis/simov/request-multipart/master.svg?style=flat-square (Build Status - Travis CI)
[coveralls-status]: https://img.shields.io/coveralls/simov/request-multipart.svg?style=flat-square (Test Coverage - Coveralls)
[codecov-status]: https://img.shields.io/codecov/c/github/simov/request-multipart.svg?style=flat-square (Test Coverage - Codecov)

@@ -85,8 +181,4 @@ [npm]: https://www.npmjs.com/package/request-multipart

[coveralls]: https://coveralls.io/github/simov/request-multipart
[codecov]: https://codecov.io/github/simov/request-multipart?branch=master
[request-compose]: https://www.npmjs.com/package/request-compose
[examples]: https://github.com/simov/request-compose#examples
[form-data]: https://tools.ietf.org/html/rfc2388
[related]: https://tools.ietf.org/html/rfc2387
[examples]: https://github.com/simov/request-multipart/blob/master/examples/multipart.js
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