File tree Expand file tree Collapse file tree 3 files changed +40
-3
lines changed
Expand file tree Collapse file tree 3 files changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,11 @@ here for compatibility with the [W3C File API Draft](http://dev.w3.org/2006/weba
182182
183183If hash calculation was set, you can read the hex digest out of this var.
184184
185+ #### Formidable.File#toJSON()
186+
187+ This method returns a JSON-representation of the file, allowing you to
188+ ` JSON.stringify() ` the file which is useful for logging and responding
189+ to requests.
185190
186191### Events
187192
Original file line number Diff line number Diff line change @@ -38,13 +38,12 @@ File.prototype.toJSON = function() {
3838 path : this . path ,
3939 name : this . name ,
4040 type : this . type ,
41- hash : this . hash ,
4241 mtime : this . lastModifiedDate ,
4342 length : this . length ,
4443 filename : this . filename ,
4544 mime : this . mime
46- }
47- }
45+ } ;
46+ } ;
4847
4948File . prototype . write = function ( buffer , cb ) {
5049 var self = this ;
Original file line number Diff line number Diff line change 1+ var common = require ( '../common' ) ;
2+ var test = require ( 'utest' ) ;
3+ var assert = common . assert ;
4+ var File = common . require ( 'file' ) ;
5+
6+ var file ;
7+ var now = new Date ;
8+ test ( 'IncomingForm' , {
9+ before : function ( ) {
10+ file = new File ( {
11+ size : 1024 ,
12+ path : '/tmp/cat.png' ,
13+ name : 'cat.png' ,
14+ type : 'image/png' ,
15+ lastModifiedDate : now ,
16+ filename : 'cat.png' ,
17+ mime : 'image/png'
18+ } )
19+ } ,
20+
21+ '#toJSON()' : function ( ) {
22+ var obj = file . toJSON ( ) ;
23+ var len = Object . keys ( obj ) . length ;
24+ assert . equal ( 1024 , obj . size ) ;
25+ assert . equal ( '/tmp/cat.png' , obj . path ) ;
26+ assert . equal ( 'cat.png' , obj . name ) ;
27+ assert . equal ( 'image/png' , obj . type ) ;
28+ assert . equal ( 'image/png' , obj . mime ) ;
29+ assert . equal ( 'cat.png' , obj . filename ) ;
30+ assert . equal ( now , obj . mtime ) ;
31+ assert . equal ( len , 8 ) ;
32+ }
33+ } ) ;
You can’t perform that action at this time.
0 commit comments