Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/form-data/isomorphic-form-data
A module to create readable `"multipart/form-data"` isomorphically in node and the browser.
https://github.com/form-data/isomorphic-form-data
Last synced: 5 days ago
JSON representation
A module to create readable `"multipart/form-data"` isomorphically in node and the browser.
- Host: GitHub
- URL: https://github.com/form-data/isomorphic-form-data
- Owner: form-data
- License: mit
- Created: 2015-08-09T04:38:48.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-07-07T10:23:21.000Z (over 3 years ago)
- Last Synced: 2024-11-03T07:02:23.168Z (10 days ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 34
- Watchers: 6
- Forks: 12
- Open Issues: 3
-
Metadata Files:
- Readme: Readme.md
- License: License
Awesome Lists containing this project
README
A library to create readable ```"multipart/form-data"``` isomorphically in node and the browser.
[xhr2-fd]: http://dev.w3.org/2006/webapi/XMLHttpRequest-2/Overview.html#the-formdata-interface
[streams2-thing]: http://nodejs.org/api/stream.html#stream_compatibility_with_older_node_versions## Install
```
npm install isomorphic-form-data
```## Usage
In this example we are constructing a form with 3 fields that contain a string,
a buffer and a file stream.``` javascript
require('isomorphic-form-data');
var fs = require('fs');var form = new FormData();
form.append('my_field', 'my value');
form.append('my_buffer', new Buffer(10));
form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
```#### node-fetch
You can submit a form using [node-fetch](https://github.com/matthew-andrews/isomorphic-fetch):
```javascript
var form = new FormData();form.append('a', 1);
fetch('http://example.com', { method: 'POST', body: form })
.then(function(res) {
return res.json();
}).then(function(json) {
console.log(json);
});
```## License
Form-Data is licensed under the MIT license.