Comparing version 0.0.7 to 0.0.8
@@ -121,7 +121,8 @@ var CombinedStream = require('combined-stream'); | ||
// fs- and request- streams have path property | ||
// or use custom filename and/or contentType | ||
// TODO: Use request's response mime-type | ||
if (value.path) { | ||
if (options.filename || value.path) { | ||
header += | ||
'; filename="' + path.basename(value.path) + '"' + FormData.LINE_BREAK + | ||
'Content-Type: ' + mime.lookup(value.path); | ||
'; filename="' + path.basename(options.filename || value.path) + '"' + FormData.LINE_BREAK + | ||
'Content-Type: ' + (options.contentType || mime.lookup(options.filename || value.path)); | ||
@@ -128,0 +129,0 @@ // http response has not |
@@ -5,3 +5,3 @@ { | ||
"description": "A module to create readable `\"multipart/form-data\"` streams. Can be used to submit forms and file uploads to other web applications.", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"repository": { | ||
@@ -12,4 +12,7 @@ "type": "git", | ||
"main": "./lib/form_data", | ||
"scripts": { | ||
"test": "node test/run.js" | ||
}, | ||
"engines": { | ||
"node": "*" | ||
"node": ">= 0.6" | ||
}, | ||
@@ -19,10 +22,10 @@ "dependencies": { | ||
"mime": "~1.2.2", | ||
"async": "~0.1.9" | ||
"async": "~0.2.7" | ||
}, | ||
"devDependencies": { | ||
"fake": "0.2.1", | ||
"far": "0.0.1", | ||
"formidable": "1.0.2", | ||
"request": "~2.9.203" | ||
"fake": "~0.2.1", | ||
"far": "~0.0.7", | ||
"formidable": "~1.0.13", | ||
"request": "~2.16.6" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# form-data | ||
# Form-Data [![Build Status](https://travis-ci.org/alexindigo/node-form-data.png?branch=master)](https://travis-ci.org/alexindigo/node-form-data) | ||
@@ -13,3 +13,5 @@ A module to create readable `"multipart/form-data"` streams. Can be used to | ||
Sorry, this isn't ready for you yet. | ||
``` | ||
npm install form-data | ||
``` | ||
@@ -106,5 +108,26 @@ ## Usage | ||
For edge cases, like POST request to URL with query string or to pass HTTP auth creadentials, object can be passed to `form.submit()` as first parameter: | ||
Form-Data can recognize and fetch all the required information from common types of streams (fs.readStream, http.response and mikeal's request), for some other types of streams you'd need to provide "file"-related information manually: | ||
``` javascript | ||
someModule.stream(function(err, stdout, stderr) { | ||
if (err) throw err; | ||
var form = new FormData(); | ||
form.append('file', stdout, { | ||
filename: 'unicycle.jpg', | ||
contentType: 'image/jpg', | ||
knownLength: 19806 | ||
}); | ||
form.submit('http://example.com/', function(err, res) { | ||
if (err) throw err; | ||
console.log('Done'); | ||
}); | ||
}); | ||
``` | ||
For edge cases, like POST request to URL with query string or to pass HTTP auth credentials, object can be passed to `form.submit()` as first parameter: | ||
``` javascript | ||
form.submit({ | ||
@@ -119,3 +142,8 @@ host: 'example.com', | ||
## TODO | ||
[xhr2-fd]: http://dev.w3.org/2006/webapi/XMLHttpRequest-2/Overview.html#the-formdata-interface | ||
- 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. |
@@ -53,3 +53,2 @@ var common = require('../common'); | ||
}).end(); | ||
@@ -59,60 +58,23 @@ | ||
// formidable is broken so let's do it manual way | ||
// | ||
// var form = new IncomingForm(); | ||
// form.uploadDir = common.dir.tmp; | ||
// form.parse(req); | ||
// form | ||
// .on('field', function(name, value) { | ||
// var field = FIELDS.shift(); | ||
// assert.strictEqual(name, field.name); | ||
// assert.strictEqual(value, field.value+''); | ||
// }) | ||
// .on('file', function(name, file) { | ||
// var field = FIELDS.shift(); | ||
// assert.strictEqual(name, field.name); | ||
// assert.strictEqual(file.name, path.basename(field.value.path)); | ||
// // mime.lookup file.NAME == 'my_file' ? | ||
// assert.strictEqual(file.type, mime.lookup(file.name)); | ||
// }) | ||
// .on('end', function() { | ||
// res.writeHead(200); | ||
// res.end('done'); | ||
// }); | ||
var form = new IncomingForm({uploadDir: common.dir.tmp}); | ||
// temp workaround | ||
var data = ''; | ||
req.setEncoding('utf8'); | ||
form.parse(req); | ||
req.on('data', function(d) { | ||
data += d; | ||
}); | ||
req.on('end', function() { | ||
// check for the fields' traces | ||
// 1st field : my_field | ||
var field = FIELDS.shift(); | ||
assert.ok( data.indexOf('form-data; name="'+field.name+'"') != -1 ); | ||
assert.ok( data.indexOf(field.value) != -1 ); | ||
// 2nd field : my_buffer | ||
var field = FIELDS.shift(); | ||
assert.ok( data.indexOf('form-data; name="'+field.name+'"') != -1 ); | ||
assert.ok( data.indexOf(field.value) != -1 ); | ||
// 3rd field : remote_file | ||
var field = FIELDS.shift(); | ||
assert.ok( data.indexOf('form-data; name="'+field.name+'"') != -1 ); | ||
assert.ok( data.indexOf('; filename="'+path.basename(remoteFile)+'"') != -1 ); | ||
// check for http://nodejs.org/images/logo.png traces | ||
assert.ok( data.indexOf('ImageReady') != -1 ); | ||
assert.ok( data.indexOf('Content-Type: '+mime.lookup(remoteFile) ) != -1 ); | ||
res.writeHead(200); | ||
res.end('done'); | ||
}); | ||
form | ||
.on('field', function(name, value) { | ||
var field = FIELDS.shift(); | ||
assert.strictEqual(name, field.name); | ||
assert.strictEqual(value, field.value+''); | ||
}) | ||
.on('file', function(name, file) { | ||
var field = FIELDS.shift(); | ||
assert.strictEqual(name, field.name); | ||
// http response doesn't have path property | ||
assert.strictEqual(file.name, path.basename(field.value.path || remoteFile)); | ||
assert.strictEqual(file.type, mime.lookup(file.name)); | ||
}) | ||
.on('end', function() { | ||
res.writeHead(200); | ||
res.end('done'); | ||
}); | ||
}); | ||
@@ -119,0 +81,0 @@ |
@@ -25,69 +25,22 @@ var common = require('../common'); | ||
// formidable is fixed on github | ||
// but still 7 month old in npm | ||
// | ||
// var form = new IncomingForm(); | ||
// form.uploadDir = common.dir.tmp; | ||
// form.parse(req); | ||
// form | ||
// .on('field', function(name, value) { | ||
// var field = FIELDS.shift(); | ||
// assert.strictEqual(name, field.name); | ||
// assert.strictEqual(value, field.value+''); | ||
// }) | ||
// .on('file', function(name, file) { | ||
// var field = FIELDS.shift(); | ||
// assert.strictEqual(name, field.name); | ||
// assert.strictEqual(file.name, path.basename(field.value.path)); | ||
// assert.strictEqual(file.type, mime.lookup(file.name)); | ||
// }) | ||
// .on('end', function() { | ||
// res.writeHead(200); | ||
// res.end('done'); | ||
// }); | ||
var form = new IncomingForm({uploadDir: common.dir.tmp}); | ||
// temp workaround | ||
var data = ''; | ||
req.setEncoding('utf8'); | ||
form.parse(req); | ||
req.on('data', function(d) { | ||
data += d; | ||
}); | ||
req.on('end', function() { | ||
// check for the fields' traces | ||
// 1st field : my_field | ||
var field = FIELDS.shift(); | ||
assert.ok( data.indexOf('form-data; name="'+field.name+'"') != -1 ); | ||
assert.ok( data.indexOf(field.value) != -1 ); | ||
// 2nd field : my_buffer | ||
var field = FIELDS.shift(); | ||
assert.ok( data.indexOf('form-data; name="'+field.name+'"') != -1 ); | ||
assert.ok( data.indexOf(field.value) != -1 ); | ||
// 3rd field : my_file | ||
var field = FIELDS.shift(); | ||
assert.ok( data.indexOf('form-data; name="'+field.name+'"') != -1 ); | ||
assert.ok( data.indexOf('; filename="'+path.basename(field.value.path)+'"') != -1 ); | ||
// check for unicycle.jpg traces | ||
assert.ok( data.indexOf('2005:06:21 01:44:12') != -1 ); | ||
assert.ok( data.indexOf('Content-Type: '+mime.lookup(field.value.path) ) != -1 ); | ||
// 4th field : remote_file | ||
var field = FIELDS.shift(); | ||
assert.ok( data.indexOf('form-data; name="'+field.name+'"') != -1 ); | ||
assert.ok( data.indexOf('; filename="'+path.basename(field.value.path)+'"') != -1 ); | ||
// check for http://nodejs.org/images/logo.png traces | ||
assert.ok( data.indexOf('ImageReady') != -1 ); | ||
assert.ok( data.indexOf('Content-Type: '+mime.lookup(remoteFile) ) != -1 ); | ||
res.writeHead(200); | ||
res.end('done'); | ||
}); | ||
form | ||
.on('field', function(name, value) { | ||
var field = FIELDS.shift(); | ||
assert.strictEqual(name, field.name); | ||
assert.strictEqual(value, field.value+''); | ||
}) | ||
.on('file', function(name, file) { | ||
var field = FIELDS.shift(); | ||
assert.strictEqual(name, field.name); | ||
assert.strictEqual(file.name, path.basename(field.value.path)); | ||
assert.strictEqual(file.type, mime.lookup(file.name)); | ||
}) | ||
.on('end', function() { | ||
res.writeHead(200); | ||
res.end('done'); | ||
}); | ||
}); | ||
@@ -94,0 +47,0 @@ |
@@ -25,66 +25,22 @@ var common = require('../common'); | ||
// formidable is fixed on github | ||
// but still 7 month old in npm | ||
// | ||
// var form = new IncomingForm(); | ||
// form.uploadDir = common.dir.tmp; | ||
// form.parse(req); | ||
// form | ||
// .on('field', function(name, value) { | ||
// var field = FIELDS.shift(); | ||
// assert.strictEqual(name, field.name); | ||
// assert.strictEqual(value, field.value+''); | ||
// }) | ||
// .on('file', function(name, file) { | ||
// var field = FIELDS.shift(); | ||
// assert.strictEqual(name, field.name); | ||
// assert.strictEqual(file.name, path.basename(field.value.path)); | ||
// // mime.lookup file.NAME == 'my_file' ? | ||
// assert.strictEqual(file.type, mime.lookup(file.name)); | ||
// }) | ||
// .on('end', function() { | ||
// res.writeHead(200); | ||
// res.end('done'); | ||
// }); | ||
var form = new IncomingForm({uploadDir: common.dir.tmp}); | ||
// temp workaround | ||
var data = ''; | ||
req.setEncoding('utf8'); | ||
req.on('data', function(d) { | ||
data += d; | ||
}); | ||
req.on('end', function() { | ||
// check for the fields' traces | ||
form.parse(req); | ||
// 1st field : my_field | ||
var field = FIELDS.shift(); | ||
assert.ok( data.indexOf('form-data; name="'+field.name+'"') != -1 ); | ||
assert.ok( data.indexOf(field.value) != -1 ); | ||
// 2nd field : my_buffer | ||
var field = FIELDS.shift(); | ||
assert.ok( data.indexOf('form-data; name="'+field.name+'"') != -1 ); | ||
assert.ok( data.indexOf(field.value) != -1 ); | ||
// 3rd field : my_file | ||
var field = FIELDS.shift(); | ||
assert.ok( data.indexOf('form-data; name="'+field.name+'"') != -1 ); | ||
assert.ok( data.indexOf('; filename="'+path.basename(field.value.path)+'"') != -1 ); | ||
// check for unicycle.jpg traces | ||
assert.ok( data.indexOf('2005:06:21 01:44:12') != -1 ); | ||
assert.ok( data.indexOf('Content-Type: '+mime.lookup(field.value.path) ) != -1 ); | ||
// 4th field : remote_file | ||
var field = FIELDS.shift(); | ||
assert.ok( data.indexOf('form-data; name="'+field.name+'"') != -1 ); | ||
assert.ok( data.indexOf('; filename="'+path.basename(field.value.path)+'"') != -1 ); | ||
// check for http://nodejs.org/images/logo.png traces | ||
assert.ok( data.indexOf('ImageReady') != -1 ); | ||
assert.ok( data.indexOf('Content-Type: '+mime.lookup(remoteFile) ) != -1 ); | ||
res.writeHead(200); | ||
res.end('done'); | ||
}); | ||
form | ||
.on('field', function(name, value) { | ||
var field = FIELDS.shift(); | ||
assert.strictEqual(name, field.name); | ||
assert.strictEqual(value, field.value+''); | ||
}) | ||
.on('file', function(name, file) { | ||
var field = FIELDS.shift(); | ||
assert.strictEqual(name, field.name); | ||
assert.strictEqual(file.name, path.basename(field.value.path)); | ||
assert.strictEqual(file.type, mime.lookup(file.name)); | ||
}) | ||
.on('end', function() { | ||
res.writeHead(200); | ||
res.end('done'); | ||
}); | ||
}); | ||
@@ -91,0 +47,0 @@ |
@@ -25,66 +25,22 @@ var common = require('../common'); | ||
// formidable is fixed on github | ||
// but still 7 month old in npm | ||
// | ||
// var form = new IncomingForm(); | ||
// form.uploadDir = common.dir.tmp; | ||
// form.parse(req); | ||
// form | ||
// .on('field', function(name, value) { | ||
// var field = FIELDS.shift(); | ||
// assert.strictEqual(name, field.name); | ||
// assert.strictEqual(value, field.value+''); | ||
// }) | ||
// .on('file', function(name, file) { | ||
// var field = FIELDS.shift(); | ||
// assert.strictEqual(name, field.name); | ||
// assert.strictEqual(file.name, path.basename(field.value.path)); | ||
// // mime.lookup file.NAME == 'my_file' ? | ||
// assert.strictEqual(file.type, mime.lookup(file.name)); | ||
// }) | ||
// .on('end', function() { | ||
// res.writeHead(200); | ||
// res.end('done'); | ||
// }); | ||
var form = new IncomingForm({uploadDir: common.dir.tmp}); | ||
// temp workaround | ||
var data = ''; | ||
req.setEncoding('utf8'); | ||
req.on('data', function(d) { | ||
data += d; | ||
}); | ||
req.on('end', function() { | ||
// check for the fields' traces | ||
form.parse(req); | ||
// 1st field : my_field | ||
var field = FIELDS.shift(); | ||
assert.ok( data.indexOf('form-data; name="'+field.name+'"') != -1 ); | ||
assert.ok( data.indexOf(field.value) != -1 ); | ||
// 2nd field : my_buffer | ||
var field = FIELDS.shift(); | ||
assert.ok( data.indexOf('form-data; name="'+field.name+'"') != -1 ); | ||
assert.ok( data.indexOf(field.value) != -1 ); | ||
// 3rd field : my_file | ||
var field = FIELDS.shift(); | ||
assert.ok( data.indexOf('form-data; name="'+field.name+'"') != -1 ); | ||
assert.ok( data.indexOf('; filename="'+path.basename(field.value.path)+'"') != -1 ); | ||
// check for unicycle.jpg traces | ||
assert.ok( data.indexOf('2005:06:21 01:44:12') != -1 ); | ||
assert.ok( data.indexOf('Content-Type: '+mime.lookup(field.value.path) ) != -1 ); | ||
// 4th field : remote_file | ||
var field = FIELDS.shift(); | ||
assert.ok( data.indexOf('form-data; name="'+field.name+'"') != -1 ); | ||
assert.ok( data.indexOf('; filename="'+path.basename(field.value.path)+'"') != -1 ); | ||
// check for http://nodejs.org/images/logo.png traces | ||
assert.ok( data.indexOf('ImageReady') != -1 ); | ||
assert.ok( data.indexOf('Content-Type: '+mime.lookup(remoteFile) ) != -1 ); | ||
res.writeHead(200); | ||
res.end('done'); | ||
}); | ||
form | ||
.on('field', function(name, value) { | ||
var field = FIELDS.shift(); | ||
assert.strictEqual(name, field.name); | ||
assert.strictEqual(value, field.value+''); | ||
}) | ||
.on('file', function(name, file) { | ||
var field = FIELDS.shift(); | ||
assert.strictEqual(name, field.name); | ||
assert.strictEqual(file.name, path.basename(field.value.path)); | ||
assert.strictEqual(file.type, mime.lookup(file.name)); | ||
}) | ||
.on('end', function() { | ||
res.writeHead(200); | ||
res.end('done'); | ||
}); | ||
}); | ||
@@ -91,0 +47,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
361727
22
147
715
15
+ Addedasync@0.2.10(transitive)
- Removedasync@0.1.22(transitive)
Updatedasync@~0.2.7