├── .gitignore ├── .npmignore ├── License ├── Makefile ├── Readme.md ├── lib ├── browser.js └── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.sublime-* 3 | *.un~ 4 | 5 | .idea 6 | 7 | sftp-config.json 8 | 9 | node_modules/ 10 | test/tmp/ 11 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.sublime-* 3 | *.un~ 4 | 5 | .idea 6 | .gitignore 7 | .npmignore 8 | .travis.yml 9 | 10 | Makefile 11 | sftp-config.json 12 | 13 | node_modules/ 14 | test/ 15 | -------------------------------------------------------------------------------- /License: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Felix Geisendörfer (felix@debuggable.com) and contributors 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL := /bin/bash 2 | 3 | test: 4 | @./test/run.js 5 | 6 | .PHONY: test 7 | 8 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | A library to create readable ```"multipart/form-data"``` isomorphically in node and the browser. 2 | 3 | [xhr2-fd]: http://dev.w3.org/2006/webapi/XMLHttpRequest-2/Overview.html#the-formdata-interface 4 | [streams2-thing]: http://nodejs.org/api/stream.html#stream_compatibility_with_older_node_versions 5 | 6 | ## Install 7 | 8 | ``` 9 | npm install isomorphic-form-data 10 | ``` 11 | 12 | ## Usage 13 | 14 | In this example we are constructing a form with 3 fields that contain a string, 15 | a buffer and a file stream. 16 | 17 | ``` javascript 18 | require('isomorphic-form-data'); 19 | var fs = require('fs'); 20 | 21 | var form = new FormData(); 22 | form.append('my_field', 'my value'); 23 | form.append('my_buffer', new Buffer(10)); 24 | form.append('my_file', fs.createReadStream('/foo/bar.jpg')); 25 | ``` 26 | 27 | #### node-fetch 28 | 29 | You can submit a form using [node-fetch](https://github.com/matthew-andrews/isomorphic-fetch): 30 | 31 | ```javascript 32 | var form = new FormData(); 33 | 34 | form.append('a', 1); 35 | 36 | fetch('http://example.com', { method: 'POST', body: form }) 37 | .then(function(res) { 38 | return res.json(); 39 | }).then(function(json) { 40 | console.log(json); 41 | }); 42 | ``` 43 | 44 | ## License 45 | 46 | Form-Data is licensed under the MIT license. 47 | -------------------------------------------------------------------------------- /lib/browser.js: -------------------------------------------------------------------------------- 1 | module.exports = window.FormData 2 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | global.FormData = module.exports = require('form-data') 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "Dylan Piercey ", 3 | "name": "isomorphic-form-data", 4 | "description": "A library to create readable \"multipart/form-data\" in node and the browser.", 5 | "version": "2.0.0", 6 | "repository": { 7 | "type": "git", 8 | "url": "git://github.com/form-data/isomorphic-form-data.git" 9 | }, 10 | "main": "./lib/index", 11 | "browser": "./lib/browser", 12 | "scripts": { 13 | "test": "./test/run.js" 14 | }, 15 | "pre-commit": [ 16 | "test" 17 | ], 18 | "dependencies": { 19 | "form-data": "^2.3.2" 20 | }, 21 | "license": "MIT" 22 | } 23 | --------------------------------------------------------------------------------