I have a problem with sending the mp3 file using axios to the backend, everything seems fine when I do console logs on the front, everything is in it, unfortunately on the backend the file field is empty (not null not undefined, just empty).
API:
const API = axios.create({baseUrl: 'http://localhost:5000'})
API.interceptors.request.use((req) => {
if (localStorage.getItem('profile')) {
req.headers.Authorization = `Bearer ${JSON.parse(localStorage.getItem('profile')).token}`;
}
return req;
})
export const addSong = (newSong) => API.post('/songs', newSong);
backend
export const addSong = async (req, res) => {
const song = req.body;
console.log(song)
const newSong = new Song({...song, creator: req.userId, createdAt: new Date().toISOString()});
try {
await newSong.save();
res.status(201).json(newSong);
} catch (error) {
res.status(409).json({ message: error.message });
}
};