{"_id":"@discordjs/form-data","_rev":"3-324b15c68590910315847f182a06deca","name":"@discordjs/form-data","dist-tags":{"latest":"3.0.1"},"versions":{"3.0.1":{"author":{"name":"Felix Geisendörfer","email":"felix@debuggable.com","url":"http://debuggable.com/"},"name":"@discordjs/form-data","description":"A library to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.","version":"3.0.1","repository":{"type":"git","url":"git://github.com/form-data/form-data.git"},"main":"./lib/form_data","browser":"./lib/browser","typings":"./index.d.ts","scripts":{"pretest":"rimraf coverage test/tmp","test":"istanbul cover test/run.js","posttest":"istanbul report lcov text","lint":"eslint lib/*.js test/*.js test/integration/*.js","report":"istanbul report lcov text","ci-lint":"is-node-modern 8 && npm run lint || is-node-not-modern 8","ci-test":"npm run test && npm run browser && npm run report","predebug":"rimraf coverage test/tmp","debug":"verbose=1 ./test/run.js","browser":"browserify -t browserify-istanbul test/run-browser.js | obake --coverage","check":"istanbul check-coverage coverage/coverage*.json","files":"pkgfiles --sort=name","get-version":"node -e \"console.log(require('./package.json').version)\""},"pre-commit":["lint","ci-test","check"],"engines":{"node":">= 6"},"dependencies":{"asynckit":"^0.4.0","combined-stream":"^1.0.8","mime-types":"^2.1.12"},"devDependencies":{"@types/node":"^12.0.10","browserify":"^13.1.1","browserify-istanbul":"^2.0.0","coveralls":"^3.0.4","cross-spawn":"^6.0.5","eslint":"^6.0.1","fake":"^0.2.2","far":"^0.0.7","formidable":"^1.0.17","in-publish":"^2.0.0","is-node-modern":"^1.0.0","istanbul":"^0.4.5","obake":"^0.1.2","puppeteer":"^1.19.0","pkgfiles":"^2.3.0","pre-commit":"^1.1.3","request":"^2.88.0","rimraf":"^2.7.1","tape":"^4.6.2","typescript":"^3.5.2"},"license":"MIT","gitHead":"b72158fbcc65a0bb2333be61090f56bf88a084f2","bugs":{"url":"https://github.com/form-data/form-data/issues"},"homepage":"https://github.com/form-data/form-data#readme","_id":"@discordjs/form-data@3.0.1","_nodeVersion":"12.16.2","_npmVersion":"6.14.4","dist":{"integrity":"sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==","shasum":"5c9e6be992e2e57d0dfa0e39979a850225fb4697","tarball":"https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz","fileCount":7,"unpackedSize":30702,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJemDxsCRA9TVsSAnZWagAAxWcP/3jSmOHFsopiQMNbPTLA\n2rk5srCqKgdKHf87gMKlqItR+dczAIQCWObTu/krCpbzReEtlVUWZmOYKCrM\n1c/lw0BB0aBWwoj8hpr8sUCDIR1JHtGmD4vPviyN1mQYsbgmbCz2+9m/TgNG\nDGF+7DqRtENxyaSGurftfuKCxrphmTtF2Z2RTQ15//PLFNS6ZVLQn5rXPHhT\nkC0B/BV5ySoiz1QGwohh2pnRIjfyIR+13+AAXWh9BDygHYp9YefINPgr0EOC\nDuaF9iEhK/hL36OAiYh0IjrmUmJd70/0uGLDyqXpUDRlVkJHKJW6LSuh9TnT\nDRCcH9n5pnssKkRtQqtfQpvD6pIOiZsxNG2qIc6K0TrwfVAriMa5Wi5H8FiR\naTwP1NPee+q6nOrAcCFq9pAN92jNg+P17Qr5qLvpOP9fYajhESgz/RFdW1ml\nre21qK2bd1XN/CoYdC1kc11oVl+T/P70E9fgCB0BtkMUlKASPy8ls8M5nzWb\n/8KvgbdasjvczqgtgC7nEChCjT7SJZa2diqvCOQe1s7apqFFYJBwisaE1O1e\nnJGQexrGoz6pTpbvutAMgVbkIGOzv2h+6KL/uUC2ZNiaHI4jXXQPLY2J3ANO\necFBPQuzuOe8JlEB7gI1FQaI+DkV/gg6H8QApY/sWnA7Sma6jhgrMqNlNF3K\nmU4N\r\n=BcwX\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDIOIeCyYGmVwG9cwpcKFzQI72iRvdZMfHH0CEezkc5vwIhALDC1NQ/5G4YwdnaW2V+w0e+uqFuZ9j2jL0sD6hcX601"}]},"maintainers":[{"name":"gawdl3y","email":"Gawdl3y@gawdl3y.com"},{"name":"crawl","email":"icrawltogo@gmail.com"},{"name":"hydrabolt","email":"amishshah.2k@gmail.com"}],"_npmUser":{"name":"crawl","email":"icrawltogo@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/form-data_3.0.1_1587035243490_0.1633608185746951"},"_hasShrinkwrap":false,"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."}},"time":{"created":"2020-04-16T11:07:23.376Z","3.0.1":"2020-04-16T11:07:23.698Z","modified":"2022-07-17T22:08:39.852Z"},"maintainers":[{"email":"icrawltogo@gmail.com","name":"crawl"},{"email":"amishshah.2k@gmail.com","name":"hydrabolt"}],"description":"A library to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.","homepage":"https://github.com/form-data/form-data#readme","repository":{"type":"git","url":"git://github.com/form-data/form-data.git"},"author":{"name":"Felix Geisendörfer","email":"felix@debuggable.com","url":"http://debuggable.com/"},"bugs":{"url":"https://github.com/form-data/form-data/issues"},"license":"MIT","readme":"# Form-Data [![NPM Module](https://img.shields.io/npm/v/form-data.svg)](https://www.npmjs.com/package/form-data) [![Join the chat at https://gitter.im/form-data/form-data](http://form-data.github.io/images/gitterbadge.svg)](https://gitter.im/form-data/form-data)\n\nA library to create readable ```\"multipart/form-data\"``` streams. Can be used to submit forms and file uploads to other web applications.\n\nThe API of this library is inspired by the [XMLHttpRequest-2 FormData Interface][xhr2-fd].\n\n[xhr2-fd]: http://dev.w3.org/2006/webapi/XMLHttpRequest-2/Overview.html#the-formdata-interface\n\n[![Linux Build](https://img.shields.io/travis/form-data/form-data/master.svg?label=linux:6.x-12.x)](https://travis-ci.org/form-data/form-data)\n[![MacOS Build](https://img.shields.io/travis/form-data/form-data/master.svg?label=macos:6.x-12.x)](https://travis-ci.org/form-data/form-data)\n[![Windows Build](https://img.shields.io/travis/form-data/form-data/master.svg?label=windows:6.x-12.x)](https://travis-ci.org/form-data/form-data)\n\n[![Coverage Status](https://img.shields.io/coveralls/form-data/form-data/master.svg?label=code+coverage)](https://coveralls.io/github/form-data/form-data?branch=master)\n[![Dependency Status](https://img.shields.io/david/form-data/form-data.svg)](https://david-dm.org/form-data/form-data)\n\n## Install\n\n```\nnpm install --save form-data\n```\n\n## Usage\n\nIn this example we are constructing a form with 3 fields that contain a string,\na buffer and a file stream.\n\n``` javascript\nvar FormData = require('form-data');\nvar fs = require('fs');\n\nvar form = new FormData();\nform.append('my_field', 'my value');\nform.append('my_buffer', new Buffer(10));\nform.append('my_file', fs.createReadStream('/foo/bar.jpg'));\n```\n\nAlso you can use http-response stream:\n\n``` javascript\nvar FormData = require('form-data');\nvar http = require('http');\n\nvar form = new FormData();\n\nhttp.request('http://nodejs.org/images/logo.png', function(response) {\n  form.append('my_field', 'my value');\n  form.append('my_buffer', new Buffer(10));\n  form.append('my_logo', response);\n});\n```\n\nOr @mikeal's [request](https://github.com/request/request) stream:\n\n``` javascript\nvar FormData = require('form-data');\nvar request = require('request');\n\nvar form = new FormData();\n\nform.append('my_field', 'my value');\nform.append('my_buffer', new Buffer(10));\nform.append('my_logo', request('http://nodejs.org/images/logo.png'));\n```\n\nIn order to submit this form to a web application, call ```submit(url, [callback])``` method:\n\n``` javascript\nform.submit('http://example.org/', function(err, res) {\n  // res – response object (http.IncomingMessage)  //\n  res.resume();\n});\n\n```\n\nFor more advanced request manipulations ```submit()``` method returns ```http.ClientRequest``` object, or you can choose from one of the alternative submission methods.\n\n### Custom options\n\nYou can provide custom options, such as `maxDataSize`:\n\n``` javascript\nvar FormData = require('form-data');\n\nvar form = new FormData({ maxDataSize: 20971520 });\nform.append('my_field', 'my value');\nform.append('my_buffer', /* something big */);\n```\n\nList of available options could be found in [combined-stream](https://github.com/felixge/node-combined-stream/blob/master/lib/combined_stream.js#L7-L15)\n\n### Alternative submission methods\n\nYou can use node's http client interface:\n\n``` javascript\nvar http = require('http');\n\nvar request = http.request({\n  method: 'post',\n  host: 'example.org',\n  path: '/upload',\n  headers: form.getHeaders()\n});\n\nform.pipe(request);\n\nrequest.on('response', function(res) {\n  console.log(res.statusCode);\n});\n```\n\nOr if you would prefer the `'Content-Length'` header to be set for you:\n\n``` javascript\nform.submit('example.org/upload', function(err, res) {\n  console.log(res.statusCode);\n});\n```\n\nTo use custom headers and pre-known length in parts:\n\n``` javascript\nvar CRLF = '\\r\\n';\nvar form = new FormData();\n\nvar options = {\n  header: CRLF + '--' + form.getBoundary() + CRLF + 'X-Custom-Header: 123' + CRLF + CRLF,\n  knownLength: 1\n};\n\nform.append('my_buffer', buffer, options);\n\nform.submit('http://example.com/', function(err, res) {\n  if (err) throw err;\n  console.log('Done');\n});\n```\n\nForm-Data can recognize and fetch all the required information from common types of streams (```fs.readStream```, ```http.response``` and ```mikeal's request```), for some other types of streams you'd need to provide \"file\"-related information manually:\n\n``` javascript\nsomeModule.stream(function(err, stdout, stderr) {\n  if (err) throw err;\n\n  var form = new FormData();\n\n  form.append('file', stdout, {\n    filename: 'unicycle.jpg', // ... or:\n    filepath: 'photos/toys/unicycle.jpg',\n    contentType: 'image/jpeg',\n    knownLength: 19806\n  });\n\n  form.submit('http://example.com/', function(err, res) {\n    if (err) throw err;\n    console.log('Done');\n  });\n});\n```\n\nThe `filepath` property overrides `filename` and may contain a relative path. This is typically used when uploading [multiple files from a directory](https://wicg.github.io/entries-api/#dom-htmlinputelement-webkitdirectory).\n\nFor edge cases, like POST request to URL with query string or to pass HTTP auth credentials, object can be passed to `form.submit()` as first parameter:\n\n``` javascript\nform.submit({\n  host: 'example.com',\n  path: '/probably.php?extra=params',\n  auth: 'username:password'\n}, function(err, res) {\n  console.log(res.statusCode);\n});\n```\n\nIn case you need to also send custom HTTP headers with the POST request, you can use the `headers` key in first parameter of `form.submit()`:\n\n``` javascript\nform.submit({\n  host: 'example.com',\n  path: '/surelynot.php',\n  headers: {'x-test-header': 'test-header-value'}\n}, function(err, res) {\n  console.log(res.statusCode);\n});\n```\n\n### Methods\n\n- [_Void_ append( **String** _field_, **Mixed** _value_ [, **Mixed** _options_] )](https://github.com/form-data/form-data#void-append-string-field-mixed-value--mixed-options-).\n- [_Headers_ getHeaders( [**Headers** _userHeaders_] )](https://github.com/form-data/form-data#array-getheaders-array-userheaders-)\n- [_String_ getBoundary()](https://github.com/form-data/form-data#string-getboundary)\n- [_Buffer_ getBuffer()](https://github.com/form-data/form-data#buffer-getbuffer)\n- [_Integer_ getLengthSync()](https://github.com/form-data/form-data#integer-getlengthsync)\n- [_Integer_ getLength( **function** _callback_ )](https://github.com/form-data/form-data#integer-getlength-function-callback-)\n- [_Boolean_ hasKnownLength()](https://github.com/form-data/form-data#boolean-hasknownlength)\n- [_Request_ submit( _params_, **function** _callback_ )](https://github.com/form-data/form-data#request-submit-params-function-callback-)\n- [_String_ toString()](https://github.com/form-data/form-data#string-tostring)\n\n#### _Void_ append( **String** _field_, **Mixed** _value_ [, **Mixed** _options_] )\nAppend data to the form. You can submit about any format (string, integer, boolean, buffer, etc.). However, Arrays are not supported and need to be turned into strings by the user.\n```javascript\nvar form = new FormData();\nform.append( 'my_string', 'my value' );\nform.append( 'my_integer', 1 );\nform.append( 'my_boolean', true );\nform.append( 'my_buffer', new Buffer(10) );\nform.append( 'my_array_as_json', JSON.stringify( ['bird','cute'] ) )\n```\n\nYou may provide a string for options, or an object.\n```javascript\n// Set filename by providing a string for options\nform.append( 'my_file', fs.createReadStream('/foo/bar.jpg'), 'bar.jpg' );\n\n// provide an object.\nform.append( 'my_file', fs.createReadStream('/foo/bar.jpg'), {filename: 'bar.jpg', contentType: 'image/jpeg', knownLength: 19806} );\n```\n\n#### _Headers_ getHeaders( [**Headers** _userHeaders_] )\nThis method adds the correct `content-type` header to the provided array of `userHeaders`.  \n\n#### _String_ getBoundary()\nReturn the boundary of the formData. A boundary consists of 26 `-` followed by 24 numbers\nfor example:\n```javascript\n--------------------------515890814546601021194782\n```\n_Note: The boundary must be unique and may not appear in the data._\n\n#### _Buffer_ getBuffer()\nReturn the full formdata request package, as a Buffer. You can insert this Buffer in e.g. Axios to send multipart data.\n```javascript\nvar form = new FormData();\nform.append( 'my_buffer', Buffer.from([0x4a,0x42,0x20,0x52,0x6f,0x63,0x6b,0x73]) );\nform.append( 'my_file', fs.readFileSync('/foo/bar.jpg') );\n\naxios.post( 'https://example.com/path/to/api',\n            form.getBuffer(),\n            form.getHeaders()\n          )\n```\n**Note:** Because the output is of type Buffer, you can only append types that are accepted by Buffer: *string, Buffer, ArrayBuffer, Array, or Array-like Object*. A ReadStream for example will result in an error.\n\n#### _Integer_ getLengthSync()\nSame as `getLength` but synchronous.\n\n_Note: getLengthSync __doesn't__ calculate streams length._\n\n#### _Integer_ getLength( **function** _callback_ )\nReturns the `Content-Length` async. The callback is used to handle errors and continue once the length has been calculated\n```javascript\nthis.getLength(function(err, length) {\n  if (err) {\n    this._error(err);\n    return;\n  }\n\n  // add content length\n  request.setHeader('Content-Length', length);\n\n  ...\n}.bind(this));\n```\n\n#### _Boolean_ hasKnownLength()\nChecks if the length of added values is known.\n\n#### _Request_ submit( _params_, **function** _callback_ )\nSubmit the form to a web application.\n```javascript\nvar form = new FormData();\nform.append( 'my_string', 'Hello World' );\n\nform.submit( 'http://example.com/', function(err, res) {\n  // res – response object (http.IncomingMessage)  //\n  res.resume();\n} );\n```\n\n#### _String_ toString()\nReturns the form data as a string. Don't use this if you are sending files or buffers, use `getBuffer()` instead.\n\n### Integration with other libraries\n\n#### Request\n\nForm submission using  [request](https://github.com/request/request):\n\n```javascript\nvar formData = {\n  my_field: 'my_value',\n  my_file: fs.createReadStream(__dirname + '/unicycle.jpg'),\n};\n\nrequest.post({url:'http://service.com/upload', formData: formData}, function(err, httpResponse, body) {\n  if (err) {\n    return console.error('upload failed:', err);\n  }\n  console.log('Upload successful!  Server responded with:', body);\n});\n```\n\nFor more details see [request readme](https://github.com/request/request#multipartform-data-multipart-form-uploads).\n\n#### node-fetch\n\nYou can also submit a form using [node-fetch](https://github.com/bitinn/node-fetch):\n\n```javascript\nvar form = new FormData();\n\nform.append('a', 1);\n\nfetch('http://example.com', { method: 'POST', body: form })\n    .then(function(res) {\n        return res.json();\n    }).then(function(json) {\n        console.log(json);\n    });\n```\n\n#### axios\n\nIn Node.js you can post a file using [axios](https://github.com/axios/axios):\n```javascript\nconst form = new FormData();\nconst stream = fs.createReadStream(PATH_TO_FILE);\n\nform.append('image', stream);\n\n// In Node.js environment you need to set boundary in the header field 'Content-Type' by calling method `getHeaders`\nconst formHeaders = form.getHeaders();\n\naxios.post('http://example.com', form, {\n  headers: {\n    ...formHeaders,\n  },\n})\n.then(response => response)\n.catch(error => error)\n```\n\n## Notes\n\n- ```getLengthSync()``` method DOESN'T calculate length for streams, use ```knownLength``` options as workaround.\n- ```getLength(cb)``` will send an error as first parameter of callback if stream length cannot be calculated (e.g. send in custom streams w/o using ```knownLength```).\n- ```sbumit``` will not add `content-length` if form length is unknown or not calculable.\n- Starting version `2.x` FormData has dropped support for `node@0.10.x`.\n- Starting version `3.x` FormData has dropped support for `node@4.x`.\n\n## License\n\nForm-Data is released under the [MIT](License) license.\n","readmeFilename":"Readme.md"}