2
我的表單很簡單。它採用ng-flow來處理文件上傳:busboy不會收到上傳的文件
<form class="form-horizontal" enctype="multipart/form-data">
<div flow-init="{target: '/test', testChunks: false, query: {'_csrf': '{{csrf}}', 'somestring': 'teststring'} }"
flow-files-submitted="data.flow.upload()"
flow-name="data.flow">
<input type="file" flow-btn/>
</div>
</form>
一旦圖像被選中,ng-flow
會做一個POST到目標路徑。看起來像被送往因爲請求負載有一堆的東西,如:
1048576
------WebKitFormBoundaryw2YAG9m602ICPd0Q
Content-Disposition: form-data; name="flowCurrentChunkSize"
圖像不是很大(〜1MB)
在一側的NodeJS(含快遞):
var busboy = require('connect-busboy')({
limits: {
fileSize: 10 * 1024 * 1024
}
});
router.post('/test', busboy, function(req, res) {
console.log('test called');
console.log(req.busboy);
if (req.busboy) {
req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
console.log("this is fieldname: " + fieldname);
});
req.busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) {
console.log('Field [' + fieldname + ']: value: ' + inspect(val));
});
}
res.json();
});
req.busboy
返回一個對象完整的東西,但req.busboy.on('file'...
和req.busboy.on('field'...)
永遠不會觸發。
爲什麼busboy看不到我的琴絃和圖像?