问题:结果上传的json文件包含卷曲边界信息。
要求:发布的文件应该是服务器端上传的文件。
堆叠:Busboy(https://github.com/mscdex/busboy),Node,Express,cURL
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.post('/foo', function(req, res) {
// some logic
if (req.busboy) {
req.pipe(req.busboy);
file.pipe(fs.createWriteStream(fpath));
fstream.on('close', function() {
deferred.resolve(fpath);
});
//more logic
}
});

curl http://localhost:3000/foo -v -X POST -F "file=@file.json"
我选择了一个名为multer
的模块
var multer = require('multer');
var upload = multer({ dest: 'uploads/' });
router.post('/upload', upload.single('file'), function (req, res) {
if (!req.file) {
throw 'No file
}
res.send('success. file is at: %s', req.file.path);
});
/*
works with curl request like so:
curl http://localhost:3000/upload \
-X POST \
-F "file=@npm-shrinkwrap.json"
*/