loopback组件存储文件上传请求中止了强大的\ lib \ incoming_form.js

时间:2017-07-14 12:13:10

标签: node.js file-upload loopback formidable

我已成功配置环回的存储组件,即loopback-component-storage。我已经能够创建文件夹。但是当我尝试上传文件(使用邮递员)时,它会不断提出请求中止错误:

error:  Error: Request aborted
    at IncomingMessage.<anonymous> (E:\projects\TestProject\node_modules\formidable\lib\incoming_form.js:120:19)
    at emitNone (events.js:86:13)
    at IncomingMessage.emit (events.js:185:7)
    at abortIncoming (_http_server.js:283:11)
    at TLSSocket.serverSocketCloseListener (_http_server.js:296:5)
    at emitOne (events.js:101:20)
    at TLSSocket.emit (events.js:188:7)
    at _handle.close (net.js:498:12)
    at Socket.done (_tls_wrap.js:325:7)
    at Socket.g (events.js:291:16)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at TCP._handle.close [as _onclose] (net.js:498:12)

我还配置了SSL,因此网址为https://localhost/api/containers/container1/upload。这可能是个问题吗?我在package.json中使用以下模块。

  "dependencies": {
    "body-parser": "^1.17.1",
    "compression": "^1.6.2",
    "cors": "^2.8.1",
    "express": "^4.15.2",
    "helmet": "^3.4.1",
    "js2xmlparser": "^3.0.0",
    "loopback": "^3.4.0",
    "loopback-boot": "^2.23.0",
    "loopback-component-explorer": "^4.1.1",
    "loopback-component-storage": "^3.2.0",
    "loopback-connector-rest": "^2.1.0",
    "loopback-datasource-juggler": "^3.2.0",
    "loopback-ssl": "0.0.9",
    "multer": "^1.3.0",
    "strong-error-handler": "^2.1.0",
    "winston": "^2.3.1"
  }

server.js文件如下所示:

'use strict';

var loopback = require('loopback');
var boot = require('loopback-boot');
var loopbackSSL = require('loopback-ssl');
var bodyParser = require('body-parser');
var multer = require('multer');

var app = module.exports = loopback();
app.use(bodyParser.text());

app.start = function () {
  // start the web server
  return app.listen(function () {
    app.emit('started');
    var baseUrl = app.get('url').replace(/\/$/, '');
    console.log('Web server listening at: %s', baseUrl);
    if (app.get('loopback-component-explorer')) {
      var explorerPath = app.get('loopback-component-explorer').mountPath;
      console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
    }
  });
};

// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname, function (err) {
  if (err) throw err;

  if (require.main === module)
    return loopbackSSL.startServer(app);
});

上述任何模块都可能成为问题吗?看起来这是一个节点难以解决的问题。谁能让我知道?我们可以编写一个接受文件的远程方法吗?

2 个答案:

答案 0 :(得分:1)

我已经能够通过删除

解决此问题
app.use(bodyParser.text());

来自server.js。这些文件现在上传了。

答案 1 :(得分:1)

想要为其他观众发表评论(但我没有足够的声誉),因为我遇到了类似的问题并删除了以下内容:

app.use(multer({storage: storage}).any())

感谢您发布此信息以及您找到的解决方案,我的解决方案几乎完全相同。