I run into a problem creating my first RESTapi app.
I have a multer module included to get a file uploaded using form and everything works great until I provide the file.
If the file is not provided then my app crashes, so if someone will trigger a post route in my API to create a new entity(using curl for example) the app will crash.
It seems like file is always required when using multer to upload it.
My router.post looks like this:
router.post('/movies', upload.single('image'), function(req, res, next) {
var movie = new Movie(req.body);
movie.fileName = req.file.filename;
movie.save(function(err, movie){
if(err) return next(err);
res.json(movie);
}); });
So the question is:
Is it possible to leave the "file" field empty and still process saving data to db simply without fileName field? Thank you in advance!