我有一个使用 nodejs + express 的表单
玉档:
form(method="post", action="/upload", enctype="multipart/form-data")
input(type="file" name="image")
button(type="submit") Upload
Index.js 并非所有代码都是必需的
var formidable = require('formidable'),
http = require('http'),
util = require('util');
var fs = require('fs');
MyProject.post('/upload',function(req, res){
var form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files)
{
console.log(files);
});
当我使用 console.log(files) 结果是这样的
{ iProducto:
{ domain: null,
_events: {},
_maxListeners: 10,
size: 1262294,
path: 'C:\\DOCUME~1\\ADMINI~1\\CONFIG~1\\Temp\\556696bb1c0c6a54362b746c4445
45ca',
name: 'Dibujo.bmp',
type: 'image/bmp',
hash: null,
lastModifiedDate: Mon Jun 09 2014 21:25:42 GMT-0100 (Hora estándar de Cabo
Verde),
_writeStream:
{ _writableState: [Object],
writable: true,
domain: null,
_events: {},
_maxListeners: 10,
path: 'C:\\DOCUME~1\\ADMINI~1\\CONFIG~1\\Temp\\556696bb1c0c6a54362b746c4
44545ca',
fd: null,
flags: 'w',
mode: 438,
start: undefined,
pos: undefined,
bytesWritten: 1262294,
closed: true } } }
现在没关系,但我需要文件名,如果我使用 console.log(files.name) 结果是未定义的,我怎样才能得到名称值