使用flow.js服务器上传文件获取响应404

时间:2017-02-09 08:54:57

标签: javascript angularjs node.js ng-flow

我正在使用flow.js将文件上传到服务器,目前我只上传一个文件,如果我收到我发送的文件,请检查我的上传路径。

所以在角度方面,我有这样的事情:

<div class="container">
  <h1>flow image example</h1>
  <hr class="soften"/>

  <div>
    <div class="thumbnail" ng-hide="$flow.files.length">
      <img src="http://www.placehold.it/200x150/EFEFEF/AAAAAA&text=no+image" />
    </div>
    <div class="thumbnail" ng-show="$flow.files.length">
      <img flow-img="$flow.files[0]" />
    </div>
    <div>
     <span class="btn btn-primary" ng-hide="$flow.files.length" flow-btn flow-attrs="{accept:'image/*'}">Select image</span>
      <span class="btn btn-primary" ng-show="$flow.files.length" flow-btn flow-attrs="{accept:'image/*'}">Change</span>
      <span class="btn btn-danger" ng-show="$flow.files.length"
         ng-click="$flow.cancel()">
        Remove
      </span>
    </div>
    <p>
      Only PNG,GIF,JPG files allowed.
    </p>
  </div>
</div>

我没有出现问题注入了ng-flow模块,然后在我的角度控制器端,我使用app.config,如下所示:

app.config(['flowFactoryProvider', function (flowFactoryProvider) {
  flowFactoryProvider.defaults = {
    target: 'http://localhost:8080/upload',
    permanentErrors: [404, 500, 501],
    maxChunkRetries: 1,
    chunkRetryInterval: 5000,
    simultaneousUploads: 4
  };
  flowFactoryProvider.on('catchAll', function (event) {
    console.log('catchAll', arguments);
  });
  // Can be used with different implementations of Flow.js
  // flowFactoryProvider.factory = fustyFlowFactory;
}]);

感觉这方面至少工作,因为我从服务器端收到错误,这是我得到的错误:

GET http://localhost:8080/upload?flowChunkNumber=1&flowChunkSize=1048576&flowCu…-1692jpg&flowFilename=1692.jpg&flowRelativePath=1692.jpg&flowTotalChunks=1 404 (Not Found)

最后我在路由器中得到了这个

router.post('/upload',multipartMiddleware ,function (req, res) {
  flow.post(req, function(status, filename, original_filename, identifier) {
    console.log('POST', status, original_filename, identifier);
    if (ACCESS_CONTROLL_ALLOW_ORIGIN) {
      res.header("Access-Control-Allow-Origin", "*");
    }
    res.status(status).send();
  });
});

如果有人可以给我一个tipe,为什么它失败了我很感激:D

1 个答案:

答案 0 :(得分:0)

似乎要对POST端点发出GET请求。