如何在feathersjs中解决请求实体太大的错误?

时间:2017-11-23 07:19:50

标签: javascript node.js mongodb csv feathersjs

我在羽毛服务中上传csv文件且文件大小为203kb,它会抛出一个错误请求实体太大的错误,就像这样。

错误:

0x4d68 [0x38]: ...........  001  0..
0 0 00 00 00 0 00 000 00 ze 64s
.  0000:  07 00 00 00 00 00 40 00 19 03 00 00 01 00 00 00  .. 00 0 event: size 64 bytes
.  0000:  03 00 00 00  si sisizsiz4s
.  0000:  07 00 00 00 00 00 40 00 19 0....
.  0030:  00 00 00 00 00 00 00 00 00 00 00 00 ..@.@.  0010:  19 03 00 00 [0x38]: ...........  001  0..
0 0 00 00 00 0 00 000 00 ze 64s
.  0000:  07 00 00 00 00 00 40 00 100 00 00 00 00  ..............0 0 0x4d28 [0x40]: PERF_RECORD_FORK(135:135):(2:62)

0x4d68 [0x38]: ...........  001  0..
0 0 00 00 00 0 00 000 00 00 00 00: PERORD_FORK(135:135):(2:2)
我正在写这样的中间件代码,但我无法解决

app.js:

{
    "name": "GeneralError",
    "message": "request entity too large",
    "code": 500,
    "className": "general-error",
    "data": {},
    "errors": {}
}

location.service.js:

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

location.hooks.js:

// Initializes the `location` service on path `/location`
const createService = require('feathers-mongoose');
const createModel = require('../../models/location.model');
const hooks = require('./location.hooks');
const filters = require('./location.filters');
const multer = require('multer');
const multipartMiddleware = multer();

module.exports = function () {
  const app = this;
  const Model = createModel(app);
  const paginate = app.get('paginate');

  const options = {
    name: 'location',
    Model,
    paginate
  };

  // Initialize our service with any options it requires
  app.use('/location',
      multipartMiddleware.single('uri'),
        (req, res, next) => {
            req.feathers.file = req.file;
            next();
        },
    createService(options)
  );

  // Get our initialized service so that we can register hooks and filters
  const service = app.service('location');

  service.hooks(hooks);

  if (service.filter) {
    service.filter(filters);
  }
};

我使用邮递员上传csv文件

enter image description here

3 个答案:

答案 0 :(得分:3)

我在app.js文件中有更改代码

<强>之前:

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

<强>后:

app.use(bodyParser.json({limit: '100mb'}));
app.use(bodyParser.urlencoded({
  limit: '100mb',
  extended: true
}));

答案 1 :(得分:2)

我在我的Node / express应用程序中遇到了同样的问题,我使用了它,它解决了我的问题,希望它也适合你:

app.use(bodyParser.json({limit:1024102420, type:'application/json'}));

我使用了数字格式的限制,它指定了字节数

答案 2 :(得分:0)

打开app.js文件并替换以下几行

app.use(express.json());
app.use(express.urlencoded({ extended: true }));

使用

app.use(express.json({ limit: "50mb" }));
app.use(express.urlencoded({ limit: "50mb", extended: true }));