request-multipart
multipart/form-data and multipart/related support for request-compose
var compose = require('request-compose')
compose.Request.multipart = require('request-multipart')
var fs = require('fs')
;(async () => {
try {
var {body} = await compose.client({
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')}
})
console.log(body)
}
catch (err) {
console.error(err)
}
})()
Table of Contents
multipart/form-data
value can be String
, Buffer
or Stream
multipart: {
key: 'value'
}
multipart: {
key: [
'value',
'value',
]
}
multipart: {
key: {
value: 'value',
options: {filename: '', contentType: '', knownLength: 0}
}
}
multipart/related
body can be String
, Buffer
or Stream
multipart: [
{key: 'value', body: 'body'},
{key: 'value', body: 'body'},
]
Internal API
var options = {
multipart: [],
multipart: {},
contentType: 'multipart/related; boundary=',
boundary: '',
preambleCRLF: true,
postambleCRLF: true
}
var {contentType, body} = multipart(options)