I want to upload a .csv file to my REST API server. The client has the following function:
postFile() {
var formData = new FormData();
formData.append("file", this.props.submittedFile)
axios.post("http://localhost:1337/classify-csv", formData, {
headers: {
"Content-Type": "multipart/form-data",
Authorization: "Bearer " + localStorage.getItem("token"),
Email: localStorage.getItem("email")
}
}).then((response) => {
;
}, (error) => {
this.unmount();
});
}
(no worries, I will change from localStorage
to cookies soon for storing the token)
Now when receiving the data I don't know how to get the file information out of it and how to download it. This is what I got so far on the API side:
router.post("/classify-csv", checkAuthentication, async (req: Request, res: Response) => {
logging.info("Classification post", "Classification post-request called.");
try {
const classificationData = req;
// it ain't much
}
catch (err) {
console.log(err);
}
});
How can I unpack the file from (in my case) classificationData
?
I searched the internet but somehow didn't find a (good) answer.