Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
asynckit | 0.4.0 | 7.92 kB | MIT | prod | |
combined-stream | 1.0.8 | 3.97 kB | MIT | prod | |
delayed-stream | 1.0.0 | 3.38 kB | MIT | prod | |
form-data | 2.1.4 | 7.4 kB | MIT | prod | |
mime-db | 1.52.0 | 26.36 kB | MIT | prod | |
mime-types | 2.1.35 | 5.46 kB | MIT | prod |
Form-Data is a popular npm package that predominantly aids web developers in creating readable multipart/form-data
streams. Useful in the submission of forms and file uploads to other web applications, the Form-Data library is inspired by the XMLHttpRequest-2 FormData Interface. By employing this dynamic library, developers can construct forms with a variety of fields encompassing not only strings, but also buffers and file streams.
To utilize the Form-Data library, developers need to first install it via npm using the command npm install --save form-data
.
Code usage examples in JavaScript are as follows:
Constructing a form with three fields:
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'));
Using http-response stream:
var FormData = require('form-data');
var http = require('http');
var form = new FormData();
http.request('http://nodejs.org/images/logo.png', function(response) {
form.append('my_field', 'my.value');
form.append('my_buffer', new Buffer(10));
form.append('my_logo', response);
});
Submitting the form to a web application:
form.submit('http://example.org/', function(err, res) {
// res – response object (http.IncomingMessage) //
res.resume();
});
The extensive documentation for the Form-Data library can be found on the GitHub page. Not only does it provide a myriad of usage examples, but it also includes a list of available options, outlines several alternative submission methods, and details the methods available within the library. It serves as an exceptional resource for anyone seeking to understand or implement the Form-Data library.