expressjs / expressjs/multer

I try everyhing. req.files undefined !

Open
#1,016 6 comments 4 reactions 0 assignees View on GitHub
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,
});
}
);

```
![image](https://user-images.githubusercontent.com/25014707/122951360-e3bf2c80-d385-11eb-8830-0657396a48b7.png)

![image](https://user-images.githubusercontent.com/25014707/122951159-bffbe680-d385-11eb-8c89-ef2c169f358c.png)

Contributor guide

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.