I try everyhing. req.files undefined !
- Dominant language
- JavaScript
- Stars
- 12.1k
- Forks
- 1.1k
- Avg merge
- 8d 2h
- Merged PRs (30d)
- 21
Description
Hello friends;
I spent all day on this. I would be happy if you help. My codes are constantly coming as req.files undefined below and I think the image comes on the body. I will try to explain with 1 picture. I am making the post as form-data via postman. No results please help!
```
const express = require("express");
const app = express();
let configSync = require("./Config/sync");
app.use(cors());
/* CONFIG SYNC */
// ############################## ROUTE PATHS
let Global = require("./Server/Routes/Global");
let Publisher = require("./Server/Routes/Publisher");
let Ecommerce = require("./Server/Routes/Ecommerce");
app.use(express.static("static"));
app.use(express.json({ limit: "100mb" }));
app.use(express.urlencoded({ extended: false }));
app.use("/api/global", Global); //
app.use("/api/publisher", Publisher); //
app.use("/api/ecommerce", Ecommerce); //
//##################################################################
sequelize.sync({ logging: false }).then(() => {
configSync();
app.listen(process.env.PORT, () => {
console.log(`###### SERVER RUNNING ON PORT: ${process.env.PORT} #######`);
});
});
```
in the Publisher File
```
var express = require("express");
let { sequelize, Op } = require("../../Models");
var Publisher = express.Router();
let Controller = require("../Classes/Controllers");
let OnlyAdmin = require("../../Middlewares/OnlyAdmin");
const multer = require("multer");
var upload = multer({ dest: "./uploads" });
Publisher.post(
"/setanewpublish",
upload.array("files", 2),
async (req, res) => {
console.log('BODY',req.body); // Somethings like images
console.log('FILES',req.files); // Undefined
res.send({
result: true,
});
}
);
```


Contributor guide
Research direction
Start with the Publisher route in Server/Routes/Publisher and the upload middleware configuration shown in the issue. Reproduce the request from Postman using the provided route and inspect the request body and files at the handler; done means the documented multipart upload produces the expected file entries in req.files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100