Node post message with large body (1.3 mb) error : 413 Request Entity Too Large

4.8k views Asked by At

with fiddler Im creating post message with header

content-Type application/text-enriched

app.post('/books',function(req,res){
        var writeStream  = fs.createWriteStream('C://Books.txt' ,{ flags : 'w' });
        writeStream.write(req.body)

I was able to stops in debug in var writestream but when i excute this line I got error Entity is too large

there is some technique to overcome this problem? I wanted just to send large text file...

after reading some posts I've added the following which doesnt help...

var bodyParser = require('body-parser');

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

UPDATE

I've also tried with the following

  app.use(bodyParser.raw({ type: 'application/text-enriched' }));
    app.use( bodyParser.raw({limit: '10mb'}) );
    app.use(bodyParser.urlencoded({     
        extended: true,
        keepExtensions: true,
        limit: '10mb', 
        defer: true
    }));

also got the same error...413 Request Entity Too Large

1

There are 1 answers

3
krampstudio On BEST ANSWER

According to the body-parser documentation, you have to configure it regarding the content-type of your request. In your case, something like

app.use( bodyParser.raw({limit: '1mb'}) );   

or may be text

app.use( bodyParser.text({
    type : 'application/text-enriched', 
    limit: '1mb'
}) );