'problem with object files undefined after change bodyparser in app.js in nodejs

I have the object files undefined after change bodyparser in app.js in nodejs

// Middlewares

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

//Middlewares deprecated
//  app.use(bodyParser.urlencoded({ extended: false }));
//  app.use(bodyParser.json());

I am using express "express": "^4.16.4",

How I can setup properly bodyparser to upload an image to nodejs?

room.js controller

var fs = require('fs');
var path = require('path');

room.js routes

var multipart = require('connect-multiparty');
var md_upload = multipart({ uploadDir: './uploads/rooms' });
router.post('/upload-avatar',  md_upload, RoomController.uploadAvatar);

something is very weird with this files undefined



Solution 1:[1]

Yeah, no need to use body-parser, its added back again to express

To allow image upload with more size, I recommend you use the limit property and give it a value of like 30MB

for example

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

This was quoted from body-parser npm

limit: Controls the maximum request body size. If this is a number, then the value specifies the number of bytes; if it is a string, the value is passed to the bytes library for parsing. Defaults to '100kb'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 programmer