I have a file upload API. It works fine when I upload a file using the binary option using postman as seen in the screenshot below.
But when I try to call this post request via axios, the file seems to be corrupted. Can someone guide me on how to send file as binary as seen in postman.
let pickFrom = path.join(__dirname, '../sampleVideos', path.basename(filename));
let formData = new FormData();
formData.append('file', fs.createReadStream(pickFrom));
const getLength = promisify(formData.getLength.bind(formData))
const contentLength = await getLength()
let config = {
headers : {
'content-length': contentLength,
...formData.getHeaders()
},
maxBodyLength: Infinity
}
let url = domain + '/api/video/upload/' + videometa._id;
const response = axios.post(`${url}`, formData, config);
