8

This is an axios POST request in my React project. labelIDs is a long array whose length is around 8000.

    axios.post('http://localhost:3000/api/filter', {
      'ids': labelIDs,
      'like_ratio_range': ["0", "1"]
    })

I've tried body-parserbut it didn't solve the problem. Any idea how to config axios post body limit?

Or should this API be better designed?

Jiayang
  • 648
  • 7
  • 12
  • You need to configure the body limit for requests on the server. – Chava Geldzahler Nov 10 '17 at 01:40
  • @ChavaG will I be able to config on axios? or only on the backend server – Jiayang Nov 10 '17 at 01:49
  • The error is coming from the server. The server needs to be configured for the type of requests you want it to handle. – Chava Geldzahler Nov 10 '17 at 01:53
  • sounds like the server needs to be configured on the backend else you need to create some sort of parsing structure that sumerizes information to your backend OBVIOUSLY there is the easier solution this might help... https://stackoverflow.com/questions/25332561/node-js-express-large-body-for-bodyparser I'm assuming you're using node – Evil Dr. PorkChop Nov 10 '17 at 02:11

1 Answers1

13

The solution to this problem lies within body parser and how your middleware is set up. Body-parser's limit option will only take in effect if your content-type and type option match. It looks like you're sending regular json to the server, your bodyparser middleware should look something like this.

var express = require("express");
var bodyParser = require("body-parser");
var app = express();
app.use(bodyParser.json({limit: '100kb'}));

If the payload is still too large, increment the bodyParser.json() limit option. Try '200kb', try '300kb'. 100kb shoudld be enough though.

If this bodyParser middleware does not work, please show your body-parser middleware.