I want to upload the file on the server with some data, and if I'm right, I need to pass the file and all data in formData, and parse on the server side.
I'm also using Multer for parsing body and save the file on the server, but I don't know how to take my text data from my formData, because Multer takes and read-only file without formData with my data from Form.
How I may take all data in Multer or take form data without Multer?
FrontEnd
let file = file[0];
//some file from input
let data = {
name: 'Jhon',
job: 'Engener',
time: 12
}
let formData = new FormData();
formData.append('formData', JSON.stringy(data))
axios.post('someURL', formData);
backend
const multer = require('multer');
const fs = require('fs');
let storage = multer.diskStorage({
destanation: (req, file, callback) => {
callback(null, '/files')
},
filename: (req, file, callback) => {
callback(null, 'newFile');
}
});
let upload = multer({storage)};
api.post('/', upload.any(), (req, res) => {
});