I have an application that uploads PDF file and then the file has to be converted into Binary (in the backend without saving the file in a temp folder) to store it in a database.
I am being able to upload the file and read the data, however, I am not being able to convert it to binary.
Following is myapp.js
var upload = require("express-fileupload");
app.use(upload());
function upload_file(req, res, next) {
console.log('here');
if (!req.files) {
res.send({
status: false,
message: 'No file uploaded'
});
}else if (req.method == "POST") {
console.log('here');
var form = new formidable.IncomingForm();
console.log(form);
let file = req.files.fileToUpload;
console.log(file);
}
}
The output of the function once a pdf file has been uploaded is:
I tried const encoded = req.files.fileToUpload.buffer.toString('base64');
and I get an error.
I also tried fs.readFileSync
but since I'm not storing the file locally, it throws an error.