Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A module to create readable `"multipart/form-data"` streams. Can be used to submit forms and file uploads to other web applications.
JavaScript Makefile
Tree: 6431c10e89

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
Makefile
Readme.md
package.json

Readme.md

form-data

A module to create readable "multipart/form-data" streams. Can be used to submit forms and file uploads to other web applications.

The API of this module is inspired by the XMLHttpRequest-2 FormData Interface.

Install

Sorry, this isn't ready for you yet.

Usage

In this example we are constructing a form with 3 fields that contain a string, a buffer and a file stream.

var FormData = require('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'));

In order to submit this form to a web application, you can use node's http client interface:

var http = require('http');

var request = http.request({
  method: 'post',
  host: 'example.org',
  path: '/upload',
  headers: form.getHeaders()
});

form.pipe(request);

request.on('response', function(res) {
  console.log(res.statusCode);
});

Or if you would prefer the 'Content-Length' header to be set for you:

form.submit('example.org/upload', function(err, res) {
  console.log(res.statusCode);
});
Something went wrong with that request. Please try again.