0

I am trying to create a web service that receives data from our school database. The connection service works fine until I try to receive the photos from the datasource.

The images come in as a base64 and I am using the following code to control the post_size:

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

This is the largest size I have used, just to make sure that data of any size can come in. This is only for testing and once I know the actual size I can adjust it accordingly.

So I have about 700 images that need to come in that are about 1MB each in size - so the 2000mb should be more than enough.

I keep getting the following message in the datasource's logs:

Error: 413 (Request Entity Too Large)

Is there a limit of expressjs, node or JSON that I am not aware off?

Would it be better to write this is PHP and use XML as the accepting format?

I would like to stick with Express and JSON if I can...

Thanks :-)

EDIT: I forgot to mention that I am running all this inside a docker container - maybe the limit is there?

jwknz
  • 6,598
  • 16
  • 72
  • 115

1 Answers1

0

I know this works for me. Use bodyParser instead. It looks like express.json and urlencoded may be deprecated.

const bodyParser = require('body-parser')
app.use(bodyParser.json({ limit: '50mb' }))
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }))
app.use(basePath + '/', routes)
cWerning
  • 583
  • 1
  • 5
  • 15
  • I thought `express.json` was based on body-parser though? Is it not the same? – jwknz Sep 16 '21 at 20:31
  • Ahh I think you may be right. – cWerning Sep 16 '21 at 20:33
  • Do you use the middleware prior to the app.use(routes) ?? – cWerning Sep 16 '21 at 20:34
  • Yes - the app.use is right under the variable declarations at the top. – jwknz Sep 16 '21 at 20:34
  • I just realised that I didn't mentioned that I am using docker containers for my app - could that impact it? – jwknz Sep 16 '21 at 20:41
  • One thing that I can think to do is make the limit really small and send a normal file. If it doesn't throw an error maybe the middleware isn't being used for whatever reason. – cWerning Sep 16 '21 at 20:47
  • One more thing - there's definitely not any other body parsers being used that could overwrite you limits? See https://stackoverflow.com/questions/19917401/error-request-entity-too-large – cWerning Sep 16 '21 at 21:02
  • No - I had a look at this and there is nothing conflicting happening. I am not sure if there is a setting on the server itself, so I am investigating that now. – jwknz Sep 17 '21 at 01:50