Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

form-data

Package Overview
Dependencies
Maintainers
6
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

form-data - npm Package Compare versions

Comparing version 1.0.0-rc2 to 1.0.0-rc3

71

lib/form_data.js

@@ -22,5 +22,8 @@ var CombinedStream = require('combined-stream');

FormData.LINE_BREAK = '\r\n';
FormData.DEFAULT_CONTENT_TYPE = 'application/octet-stream';
FormData.prototype.append = function(field, value, options) {
options = options || {};
options = (typeof options === 'string')
? { filename: options }
: options || {};

@@ -137,5 +140,2 @@ var append = CombinedStream.prototype.append.bind(this);

FormData.prototype._multiPartHeader = function(field, value, options) {
var boundary = this.getBoundary();
var header = '';
// custom header specified (as string)?

@@ -145,26 +145,49 @@ // it becomes responsible for boundary

if (options.header != null) {
header = options.header;
} else {
header += '--' + boundary + FormData.LINE_BREAK +
'Content-Disposition: form-data; name="' + field + '"';
return options.header;
}
// fs- and request- streams have path property
// or use custom filename and/or contentType
// TODO: Use request's response mime-type
if (options.filename || value.path) {
header +=
'; filename="' + path.basename(options.filename || value.path) + '"' + FormData.LINE_BREAK +
'Content-Type: ' + (options.contentType || mime.lookup(options.filename || value.path));
var contents = '';
var headers = {
'Content-Disposition': ['form-data', 'name="' + field + '"'],
'Content-Type': []
};
// http response has not
} else if (value.readable && value.hasOwnProperty('httpVersion')) {
header +=
'; filename="' + path.basename(value.client._httpMessage.path) + '"' + FormData.LINE_BREAK +
'Content-Type: ' + value.headers['content-type'];
// fs- and request- streams have path property
// or use custom filename and/or contentType
// TODO: Use request's response mime-type
if (options.filename || value.path) {
headers['Content-Disposition'].push(
'filename="' + path.basename(options.filename || value.path) + '"'
);
headers['Content-Type'].push(
options.contentType ||
mime.lookup(options.filename || value.path) ||
FormData.DEFAULT_CONTENT_TYPE
);
// http response has not
} else if (value.readable && value.hasOwnProperty('httpVersion')) {
headers['Content-Disposition'].push(
'filename="' + path.basename(value.client._httpMessage.path) + '"'
);
headers['Content-Type'].push(
options.contentType ||
value.headers['content-type'] ||
FormData.DEFAULT_CONTENT_TYPE
);
} else if (Buffer.isBuffer(value)) {
headers['Content-Type'].push(
options.contentType ||
FormData.DEFAULT_CONTENT_TYPE
);
} else if (options.contentType) {
headers['Content-Type'].push(options.contentType);
}
for (var prop in headers) {
if (headers[prop].length) {
contents += prop + ': ' + headers[prop].join('; ') + FormData.LINE_BREAK;
}
header += FormData.LINE_BREAK + FormData.LINE_BREAK;
}
return header;
return '--' + this.getBoundary() + FormData.LINE_BREAK + contents + FormData.LINE_BREAK;
};

@@ -171,0 +194,0 @@

{
"author": "Felix Geisendörfer <felix@debuggable.com> (http://debuggable.com/)",
"name": "form-data",
"description": "A module to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.",
"version": "1.0.0-rc2",
"description": "A library to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.",
"version": "1.0.0-rc3",
"repository": {
"type": "git",
"url": "git://github.com/felixge/node-form-data.git"
"url": "git://github.com/form-data/form-data.git"
},

@@ -13,4 +13,7 @@ "main": "./lib/form_data",

"scripts": {
"test": "node test/run.js"
"test": "./test/run.js"
},
"pre-commit": [
"test"
],
"engines": {

@@ -20,5 +23,5 @@ "node": ">= 0.10"

"dependencies": {
"async": "^1.2.1",
"combined-stream": "^1.0.3",
"mime-types": "^2.1.1"
"async": "^1.4.0",
"combined-stream": "^1.0.5",
"mime-types": "^2.1.3"
},

@@ -30,4 +33,5 @@ "license": "MIT",

"formidable": "^1.0.17",
"request": "^2.57.0"
"pre-commit": "^1.0.10",
"request": "^2.60.0"
}
}

@@ -1,6 +0,6 @@

# Form-Data [![Build Status](https://travis-ci.org/felixge/node-form-data.png?branch=master)](https://travis-ci.org/felixge/node-form-data) [![Dependency Status](https://gemnasium.com/felixge/node-form-data.png)](https://gemnasium.com/felixge/node-form-data)
# Form-Data [![Join the chat at https://gitter.im/form-data/form-data](http://form-data.github.io/images/gitterbadge.svg)](https://gitter.im/form-data/form-data) [![Build Status](https://img.shields.io/travis/form-data/form-data/master.svg)](https://travis-ci.org/form-data/form-data) [![Dependency Status](https://img.shields.io/david/form-data/form-data.svg)](https://david-dm.org/form-data/form-data)
A module to create readable ```"multipart/form-data"``` streams. Can be used to submit forms and file uploads to other web applications.
A library 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][xhr2-fd].
The API of this library is inspired by the [XMLHttpRequest-2 FormData Interface][xhr2-fd].

@@ -46,3 +46,3 @@ [xhr2-fd]: http://dev.w3.org/2006/webapi/XMLHttpRequest-2/Overview.html#the-formdata-interface

Or @mikeal's request stream:
Or @mikeal's [request](https://github.com/request/request) stream:

@@ -65,3 +65,3 @@ ``` javascript

// res – response object (http.IncomingMessage) //
res.resume(); // for node-0.10.x
res.resume();
});

@@ -166,2 +166,41 @@

### Integration with other libraries
#### Request
Form submission using [request](https://github.com/request/request):
```javascript
var formData = {
my_field: 'my_value',
my_file: fs.createReadStream(__dirname + '/unicycle.jpg'),
};
request.post({url:'http://service.com/upload', formData: formData}, function(err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
console.log('Upload successful! Server responded with:', body);
});
```
For more details see [request readme](https://github.com/request/request#multipartform-data-multipart-form-uploads).
#### node-fetch
You can also submit a form using [node-fetch](https://github.com/bitinn/node-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);
});
```
## Notes

@@ -172,8 +211,4 @@

## TODO
- Add new streams (0.10) support and try really hard not to break it for 0.8.x.
## License
Form-Data is licensed under the MIT license.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc