我使用Flowjs和它的ng流指令上传以NodeJS为后端的文件.当我试图上传文件时,只上传tem文件夹中的文件,但注意任何类型的文件,如JPG或PNG。(flow-135601-juicy_gustinektar02l_10185jpg.1).这是代码:
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));
});
});发布于 2014-05-04 15:40:30
重新组装所有块很容易,只需将其称为:
var stream = fs.createWriteStream(filename);
r.write(identifier, stream);就这样!
但另一个问题是,什么时候应该调用这个方法?也许当所有的块都上传到tmp文件夹时。
但是,还有另一个问题,重复调用的已完成。一旦所有块都存在,就可以通过创建和锁定文件来解决这个问题。然后打电话
r.write(identifier, stream);然后清理所有块,释放锁并关闭文件。
在php服务器端库中完成了相同的应用程序:https://github.com/flowjs/flow-php-server/blob/master/src/Flow/File.php#L102。
希望这会有所帮助,我希望有人能够配合这些修复程序并更新node.js示例。
https://stackoverflow.com/questions/23384222
复制相似问题