I am struggling with a simple media (mp3/mp4) upload to a server using axios. I have an angular application that creates a formData and send this formData to node server via :
return this.http.post(this.apiURL + '/uploadFile', formData);
My server method looks like this :
app.post('/api/uploadFile', upload.single('file'), (req, res) => {
inputFile = req.file;
let fd = new FormData();
fd.append('file',inputFile.buffer, inputFile.originalname);
axios.post(uploadFileURL , fd, { headers: { 'Content-Type': 'multipart/form-data' } })
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error)
})
})
The inputFile contains the original files. The error I get now is that the request is not a multipart request...
I tried as well to define the formData differently :
formData = {
file: {
value: inputFile.buffer,
options: {
filename: inputFile.originalname,
contentType: inputFile.mimetype
}
}
};
Which brought me to a different error : 'Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found'
Am I doing something wrong ? I am wondering if this could be link to the fact that I use const bodyParser = require('body-parser'); for some of my other requests. Any help would be appreciated!
Thanks
EDIT : Here is my need and what I've done so far :
- I have a web application that allow users to upload media files.
- I have to send those files to a server, but I can not use the browser to send the request directly.
- I created a nodejs application to realize the proxy task of getting the files from the browser and sending it to my remote server.