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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM