首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flowjs文件上传- AngularJS和Node

Flowjs文件上传- AngularJS和Node
EN

Stack Overflow用户
提问于 2014-04-30 09:19:40
回答 1查看 6.6K关注 0票数 1

我使用Flowjs和它的ng流指令上传以NodeJS为后端的文件.当我试图上传文件时,只上传tem文件夹中的文件,但注意任何类型的文件,如JPG或PNG。(flow-135601-juicy_gustinektar02l_10185jpg.1).这是代码:

ANGULARJS

代码语言:javascript
复制
    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

代码语言:javascript
复制
    // 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));
  });
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-04 15:40:30

重新组装所有块很容易,只需将其称为:

代码语言:javascript
复制
     var stream = fs.createWriteStream(filename);
     r.write(identifier, stream);

就这样!

但另一个问题是,什么时候应该调用这个方法?也许当所有的块都上传到tmp文件夹时。

但是,还有另一个问题,重复调用的已完成。一旦所有块都存在,就可以通过创建和锁定文件来解决这个问题。然后打电话

代码语言:javascript
复制
    r.write(identifier, stream);

然后清理所有块,释放锁并关闭文件。

在php服务器端库中完成了相同的应用程序:https://github.com/flowjs/flow-php-server/blob/master/src/Flow/File.php#L102

希望这会有所帮助,我希望有人能够配合这些修复程序并更新node.js示例。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23384222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档