NodeJs:获取图像stream

我正在尝试阅读我的networkingAPI中的图像stream。

以下是我的代码。

var express = require('express'); var bodyParser = require('body-parser'); var app = express(); var Busboy = require('busboy'); app.use(bodyParser.json()); app.get('/', function(req, res) { res.send('Hello World!'); }); app.post('/', function(req, res){ var busboy = new Busboy({ headers: request.headers }); busboy.on('file', function(fieldname, file, filename, encoding, mimetype) { console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype); file.on('data', function(data) { console.log('File [' + fieldname + '] got ' + data.length + ' bytes'); }); file.on('end', function() { console.log('File [' + fieldname + '] Finished'); }); }); }); app.listen(3000, function() { console.log('Example app listening on port 3000!'); }); 

当我使用邮差testing上述post端点时,没有任何反应。 看来,busboy.on从来没有被调用/触发。

Busboy npm https://www.npmjs.com/package/busboy#readme

以下是我的要求。 通过提琴手追溯。

 POST http://localhost:3000/ HTTP/1.1 Host: localhost:3000 Connection: keep-alive Content-Length: 879585 Postman-Token: 1defded8-01ff-eb6e-4afa-c49f63b477db Cache-Control: no-cache Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36 Content-Type: multipart/form-data; boundary=----WebKitFormBoundarySrX3beIdojsVD2nB Accept: */* Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.8,fr-CA;q=0.6,fr;q=0.4 ------WebKitFormBoundarySrX3beIdojsVD2nB Content-Disposition: form-data; name="File"; filename="Chrysanthemum.jpg" Content-Type: image/jpeg 

似乎你已经在使用busboy ,但我仍然build议你尝试一下 ,像边界和多部分的东西不会打扰你。

但是如果你想自己打包,那么这些代码也是有用的。

另外记得检查一下 。 也许你会重写邮递员的Content-Type,这是没有必要的。

Interesting Posts