码迷,mamicode.com
首页 > Web开发 > 详细

【NodeJS】使用busboy上传文件

时间:2016-06-13 01:12:44      阅读:532      评论:0      收藏:0      [点我收藏+]

标签:

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);
});

 

【NodeJS】使用busboy上传文件

标签:

原文地址:http://www.cnblogs.com/baiyunchen/p/5126069.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!