I'm trying to upload a file and I noticed that when I put the enctype="multipart/form-data" in the form it returns an empty object, but when I remove it, it works fine.
In my app.js I used:
const app = express();
app.use(express.urlencoded({extended: true}));
app.use(express.json());
and in the controller:
const multer = require('multer');
const Grupos = mongoose.model('Grupos');
const shortid = require('shortid');
const configMulter = {
sotrage: fileStorage = multer.diskStorage({
destination: (req, file, next) => {
next(null, __dirname+'\\..\\public\\uploads\\grupos');
},
filename: (req, file, next) => {
const extension = file.mimetype.split('/')[1];
next(null, `${shortid.generate()}.${extension}`);
}
})
}
const upload = multer(configMulter).single('imagen');
exports.subirImagen = (req, res, next) => {
upload(res, req, function(error) {
if(errores){
console.log(error);
}
else{
next();
}
})
}
Could it be an ejs problem? I made very similar projects with pug and handlebars and they worked fine.