0

我使用 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();
  });
});

如果有人能给我一个提示,为什么它会失败,我非常感激:D

4

1 回答 1

0

似乎正在向 POST 端点发出 GET 请求。

于 2017-02-09T09:02:31.367 回答