@@ -5,6 +5,7 @@ re: https://github.com/felixge/node-form-data/issues/29
55
66var common = require ( '../common' ) ;
77var assert = common . assert ;
8+ var mime = require ( 'mime-types' ) ;
89var http = require ( 'http' ) ;
910var fs = require ( 'fs' ) ;
1011
@@ -20,25 +21,28 @@ var server = http.createServer(function(req, res) {
2021
2122 var form = new IncomingForm ( { uploadDir : common . dir . tmp } ) ;
2223
23- form . parse ( req ) ;
24+ form . parse ( req , function ( err , fields , files ) {
25+ assert ( ! err ) ;
26+
27+ assert ( 'my_file1' in files ) ;
28+ assert . strictEqual ( files [ 'my_file1' ] . name , options . filename ) ;
29+ assert . strictEqual ( files [ 'my_file1' ] . type , options . contentType ) ;
30+
31+ assert ( 'my_file2' in files ) ;
32+ assert . strictEqual ( files [ 'my_file2' ] . name , options . filename ) ;
33+ assert . strictEqual ( files [ 'my_file2' ] . type , mime . lookup ( options . filename ) ) ;
2434
25- form
26- . on ( 'file' , function ( name , file ) {
27- assert . strictEqual ( name , 'my_file' ) ;
28- assert . strictEqual ( file . name , options . filename ) ;
29- assert . strictEqual ( file . type , options . contentType ) ;
30- } )
31- . on ( 'end' , function ( ) {
3235 res . writeHead ( 200 ) ;
3336 res . end ( 'done' ) ;
34- } ) ;
37+ } ) ;
3538} ) ;
3639
3740
3841server . listen ( common . port , function ( ) {
3942 var form = new FormData ( ) ;
4043
41- form . append ( 'my_file' , fs . createReadStream ( common . dir . fixture + '/unicycle.jpg' ) , options ) ;
44+ form . append ( 'my_file1' , fs . createReadStream ( common . dir . fixture + '/unicycle.jpg' ) , options ) ;
45+ form . append ( 'my_file2' , fs . createReadStream ( common . dir . fixture + '/unicycle.jpg' ) , options . filename ) ;
4246
4347 form . submit ( 'http://localhost:' + common . port + '/' , function ( err , res ) {
4448 if ( err ) {
0 commit comments