My current setup involves a router and multer middleware, but I'm facing an issue where the file requested is not being created. As a result,
req.file
always remains undefined.
const multer = require('multer');
let storage = multer.memoryStorage();
function fileFilter (req, file, cb) {
if(file.mimetype === 'image/jpeg' || file.mimetype === 'image/png'){
cb(null,true);
return;
}
cb(new Error('wrong file type:not PNG or JPEG'),false);
}
const upload = multer({
storage : storage,
fileFilter : fileFilter
});
this.getServer().post('/vendor/profile/logo',upload.single('imageFile'),jwt,(req, res) => {
this.addCompanyLogo(req).then(user => {
res.status(200).send(user);
}).catch(err => {
console.log(err);
res.status(err.status).send(err.error);
});
});
I have also implemented bodyparser at the app level.
server = express();
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({ extended: true }));
server.use(cors());
When making the request using postman :
https://i.stack.imgur.com/Me8Va.png
So far, none of my attempts have been successful. I've even tried removing bodyparser and reordering the middleware without any luck.