{"id":22733472,"url":"https://github.com/strikeentco/multi-part","last_synced_at":"2025-04-14T01:54:22.502Z","repository":{"id":1748597,"uuid":"43983329","full_name":"strikeentco/multi-part","owner":"strikeentco","description":"Simple multipart/form-data implementation with automatic data type detection. Supports: Strings, Numbers, Arrays, Streams, Buffers and Vinyl.","archived":false,"fork":false,"pushed_at":"2023-02-11T09:36:58.000Z","size":462,"stargazers_count":10,"open_issues_count":9,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T01:54:15.764Z","etag":null,"topics":["form-data","javascript","nodejs","streams","vinyl"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/strikeentco.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2015-10-09T22:35:36.000Z","updated_at":"2024-10-16T16:25:52.000Z","dependencies_parsed_at":"2023-07-06T13:15:56.805Z","dependency_job_id":null,"html_url":"https://github.com/strikeentco/multi-part","commit_stats":{"total_commits":12,"total_committers":2,"mean_commits":6.0,"dds":"0.16666666666666663","last_synced_commit":"06968a326cd7921fb86acf209b591290e71418ff"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strikeentco%2Fmulti-part","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strikeentco%2Fmulti-part/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strikeentco%2Fmulti-part/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strikeentco%2Fmulti-part/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/strikeentco","download_url":"https://codeload.github.com/strikeentco/multi-part/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248809032,"owners_count":21164895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["form-data","javascript","nodejs","streams","vinyl"],"created_at":"2024-12-10T20:14:43.560Z","updated_at":"2025-04-14T01:54:22.483Z","avatar_url":"https://github.com/strikeentco.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"multi-part [![License](https://img.shields.io/npm/l/multi-part.svg)](https://github.com/strikeentco/multi-part/blob/master/LICENSE) [![npm](https://img.shields.io/npm/v/multi-part.svg)](https://www.npmjs.com/package/multi-part)\n==========\n[![Build Status](https://travis-ci.org/strikeentco/multi-part.svg)](https://travis-ci.org/strikeentco/multi-part) [![node](https://img.shields.io/node/v/multi-part.svg)](https://www.npmjs.com/package/multi-part) [![Test Coverage](https://api.codeclimate.com/v1/badges/9876ebf194e36617bcea/test_coverage)](https://codeclimate.com/github/strikeentco/multi-part/test_coverage)\n\nA `multi-part` allows you to create multipart/form-data `Stream` and `Buffer`, which can be used to submit forms and file uploads to other web applications.\n\nIt extends [`multi-part-lite`](https://github.com/strikeentco/multi-part-lite) and adds automatic data type detection.\n\nSupports: `Strings`, `Numbers`, `Arrays`, `ReadableStreams`, `Buffers` and `Vinyl`.\n\n## Install\n```sh\n$ npm install multi-part --save\n```\n\n## Usage\nUsage with `got` as `Stream`:\n\n```js\nconst got = require('got');\nconst Multipart = require('multi-part');\nconst form = new Multipart();\n\nform.append('photo', got.stream('https://avatars1.githubusercontent.com/u/2401029'));\nform.append('field', 'multi-part test');\n\n(async () =\u003e {\n  const body = await form.stream();\n  got.post('127.0.0.1:3000', { headers: form.getHeaders(), body });\n})()\n```\nUsage with `got` as `Buffer`:\n\n```js\nconst got = require('got');\nconst Multipart = require('multi-part');\nconst form = new Multipart();\n\nform.append('photo', got.stream('https://avatars1.githubusercontent.com/u/2401029'));\nform.append('field', 'multi-part test');\n\n(async () =\u003e {\n  const body = await form.buffer();\n  got.post('127.0.0.1:3000', { headers: form.getHeaders(false), body });\n})()\n```\nUsage with `http`/`https` as `Stream`:\n\n```js\nconst http = require('http');\nconst https = require('https');\nconst Multipart = require('multi-part');\nconst form = new Multipart();\n\nform.append('photo', https.request('https://avatars1.githubusercontent.com/u/2401029'));\n\n(async () =\u003e {\n  const stream = await form.stream();\n  stream.pipe(http.request({ headers: form.getHeaders(), hostname: '127.0.0.1', port: 3000, method: 'POST' }));\n})()\n```\nUsage with `http`/`https` as `Buffer`:\n\n```js\nconst http = require('http');\nconst https = require('https');\nconst Multipart = require('multi-part');\nconst form = new Multipart();\n\nform.append('photo', https.request('https://avatars1.githubusercontent.com/u/2401029'));\n\n(async () =\u003e {\n  const body = await form.buffer();\n  const req = http.request({ headers: form.getHeaders(false), hostname: '127.0.0.1', port: 3000, method: 'POST' });\n  req.end(body);\n})()\n```\n\n# API\n\n### new Multipart([options])\n### new MultipartAsync([options])\n\nConstructor.\n\n### Params:\n* **[options]** (*Object*) - `Object` with options:\n  * **[boundary]** (*String|Number*) - Custom boundary for `multipart` data. Ex: if equal `CustomBoundary`, boundary will be equal exactly `CustomBoundary`.\n  * **[boundaryPrefix]** (*String|Number*) - Custom boundary prefix for `multipart` data. Ex: if equal `CustomBoundary`, boundary will be equal something like `--CustomBoundary567689371204`.\n  * **[defaults]** (*Object*) - `Object` with defaults values:\n    * **[name]** (*String*) - File name which will be used, if `filename` is not specified in the options of `.append` method. By default `file`.\n    * **[ext]** (*String*) - File extension which will be used, if `filename` is not specified in the options of `.append` method. By default `bin`.\n    * **[type]** (*String*) - File content-type which will be used, if `contentType` is not specified in the options of `.append` method. By default `application/octet-stream`.\n\n```js\nconst Multipart = require('multi-part');\nconst { MultipartAsync } = require('multi-part');\n```\n\n### .append(name, value, [options])\n\nAdds a new data to the `multipart/form-data` stream.\n\n### Params:\n* **name** (*String|Number*) - Field name. Ex: `photo`.\n* **value** (*Mixed*) - Value can be `String`, `Number`, `Array`, `Buffer`, `ReadableStream` or even [Vynil](https://www.npmjs.com/package/vinyl).\n* **[options]** (*Object*) - Additional options:\n  * **filename**  (*String*) - File name. Ex: `anonim.jpg`.\n  * **contentType** (*String*) - File content type. It's not necessary if you have already specified file name. If you are not sure about the content type - leave `filename` and `contentType` empty and it will be automatically determined, if possible. Ex: `image/jpeg`.\n\nIf `value` is an array, `append` will be called for each value:\n```js\nform.append('array', [0, [2, 3], 1]);\n\n// similar to\n\nform.append('array', 0);\nform.append('array', 2);\nform.append('array', 3);\nform.append('array', 1);\n```\n\n`Null`, `false` and `true` will be converted to `'0'`, `'0'` and `'1'`. Numbers will be converted to strings also.\n\nFor `Buffer` and `ReadableStream` content type will be automatically determined, if it's possible, and name will be specified according to content type. If content type is `image/jpeg`, file name will be set as `file.jpeg` (if `filename` option is not specified).\u003cbr\u003eIn case content type is undetermined, content type and file name will be set as `application/octet-stream` and `file.bin`.\n\n### .stream()\n\nReturns a `Promise` with a `multipart/form-data` stream.\n\n### .buffer()\n\nReturns a `Promise` with a buffer of the `multipart/form-data` stream data.\n\n### .getBoundary()\n\nReturns the form boundary used in the `multipart/form-data` stream.\n\n```js\nform.getBoundary(); // -\u003e '--MultipartBoundary352840693617'\n```\n\n### .getLength()\n\nReturns the length of a buffer of the `multipart/form-data` stream data.\n\nShould be called after `.buffer()`;\n\nFor `.stream()` it's always `0`.\n\n```js\nawait form.buffer();\nform.getLength(); // -\u003e 12345\n```\n\n### .getHeaders(chunked = true)\n\nReturns the headers.\n\nIf you want to get correct `content-length`, you should call it after `.buffer()`. There is no way to know `content-length` of the `.stream()`, so it will be always `0`.\n\n### Params:\n* **chunked** (*Boolean*) - If `false` - headers will include `content-length` header, otherwise there will be `transfer-encoding: 'chunked'`.\n\n```js\nform.getHeaders(); // -\u003e\n//{\n//  'transfer-encoding': 'chunked',\n//  'content-type': 'multipart/form-data; boundary=\"--MultipartBoundary352840693617\"'\n//}\n```\nWith `.buffer()`:\n```js\nform.getHeaders(false); // -\u003e\n//{\n//  'content-length': '0',\n//  'content-type': 'multipart/form-data; boundary=\"--MultipartBoundary352840693617\"'\n//}\n\nawait form.buffer();\nform.getHeaders(false); // -\u003e\n//{\n//  'content-length': '12345',\n//  'content-type': 'multipart/form-data; boundary=\"--MultipartBoundary352840693617\"'\n//}\n```\n\n## License\n\nThe MIT License (MIT)\u003cbr/\u003e\nCopyright (c) 2015-2022 Alexey Bystrov\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrikeentco%2Fmulti-part","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrikeentco%2Fmulti-part","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrikeentco%2Fmulti-part/lists"}