I am trying to convert an image file into base64, so I can store in base64 string form in mongoDB.
This is how I am trying to do that:
router.post('/file_upload',function(req,res){
function base64_encode(file) {
var bitmap = fs.readFileSync(file);
return new Buffer(bitmap).toString('base64');
}
var ImageFileToSave = base64_encode(req.body.file);
console.log(ImageFileToSave);
})
On Client side:
<form action="/file_upload" method="POST" enctype="multipart/form-
data">
<input type="file" name="file" />
<input type="submit" value="Upload File" />
</form>
This is the error that I am getting
TypeError: path must be a string or Buffer
how can I convert that image file(eg:image.jpg) into base64?