【问题标题】:File upload with flow.js server get response 404使用 flow.js 服务器上传文件得到响应 404
【发布时间】:2026-02-20 10:05:01
【问题描述】:

我正在使用 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

【问题讨论】:

    标签: javascript angularjs node.js ng-flow


    【解决方案1】:

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

    【讨论】:

    • 没错,你说得对,api没有说怎么发帖,我会调查的
    • 我不断收到 flow.get 不是一个函数,你知道为什么吗?
    • 暂时不知道。
    • flow-init="{testChunks:false}" 使用这个