This is the app.post method in the index.js file which will receive the filename and I want to check if the image exists then the image name will be added to the file else it will not.
app.post('/addPost', upload.single('blogImage'), (req, res) => {
//for the written content
let data = req.body;
data.blogImageName = req.file.filename;
console.log(data);
postContent(req.body);
});
This is the html form
<form action="/addPost" enctype="multipart/form-data" method="POST" class="createPostForm">
<div>
<label for="AddImage">Add Image for the blog : </label>
<input type="file" name="blogImage" ><br>
</div>
<input type="submit" value="Add Post">
</form>
if i submit the form without uploading file then it gives an error.
How can i check if filename exists in the request?
multer
orexpress-fileupload
package. Do you only want to know how to check if user submitted file or you want to know the entire process about how to check and upload file as well?Please specify