Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Axios POST request 413 (Payload Too Large)

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?

like image 286
Jiayang Avatar asked Nov 10 '17 01:11

Jiayang


1 Answers

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.

like image 124
Cristoper Ayala Paz Avatar answered Oct 02 '22 13:10

Cristoper Ayala Paz