【NodeJS】使用busboy上传文件
router.post('/upload', function (req, res) { var busboy = new Busboy({ headers: req.headers }); busboy.on('file', function (fieldname, file, filename, encoding, mimetype) { console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype); var saveTo = path.join("C:/TestProject/node.js/TestExpress/TestExpress/TestExpress/", 'upload', path.basename(filename)); console.log(saveTo); file.pipe(fs.createWriteStream(saveTo)); console.log('jax'); }); busboy.on('field', function (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) { console.log('Field [' + fieldname + ']: value: ' + val); }); busboy.on('finish', function () { console.log('Done parsing form!'); res.writeHead(200); res.end('upload OK!'); }); req.pipe(busboy); });
西安.NET俱乐部群