1
我正在使用Flowjs及其ng-flow指令以NodeJS作爲後端上載文件。當我嘗試上傳文件時,只會上傳TEM文件夾中的文件,但它會記錄任何類型的文件,如JPG或PNG。 (流135601-juicy_gustinektar02l_10185jpg.1)。這裏是代碼:Flowjs文件上傳 - AngularJS和節點
ANGULARJS
app.config(['flowFactoryProvider', function (flowFactoryProvider) {
flowFactoryProvider.defaults = {
target: 'http://localhost:8086/api/upload/',
permanentErrors: [500, 501],
maxChunkRetries: 1,
chunkRetryInterval: 5000,
simultaneousUploads: 1
};
flowFactoryProvider.on('catchAll', function (event) {
console.log('catchAll', arguments);
});
// Can be used with different implementations of Flow.js
//flowFactoryProvider.factory = fustyFlowFactory;
}]);
的NodeJS
// Handle uploads through Flow.js
app.post('/api/upload', function(req, res){
flow.post(req, function(status, filename, original_filename, identifier){
console.log('POST', status, original_filename, identifier);
res.send(200, {
// NOTE: Uncomment this funciton to enable cross-domain request.
//'Access-Control-Allow-Origin': '*'
});
});
});
// Handle cross-domain requests
// NOTE: Uncomment this funciton to enable cross-domain request.
/*
app.options('/upload', function(req, res){
console.log('OPTIONS');
res.send(true, {
'Access-Control-Allow-Origin': '*'
}, 200);
});
*/
// Handle status checks on chunks through Flow.js
app.get('/api/upload', function(req, res){
flow.get(req, function(status, filename, original_filename, identifier){
console.log('GET', status);
res.send(200, (status == 'found' ? 200 : 404));
});
});
'r'應該是什麼? – chovy
我對此也有點困惑。我明白它應該做什麼,但爲什麼這不包括在例子中呢? – flashpunk
此答案中的代碼來自[flow-node.js]中的註釋(https://github.com/flowjs/flow.js/blob/master/samples/Node.js/flow-node.js# L143)。答案是從[這裏]複製/粘貼(https://github.com/flowjs/flow.js/issues/17)。我相信它最初的寫法不正確,因爲'r'沒有意義,我相信它應該是'flow',如果這就是你命名的flow-node.js模塊。所以它應該是: 'var stream = fs.createWriteStream(filename); flow.write(identifier,stream);' – cleversprocket