I would like to download a file sent from a NodeJS server while it's being piped but I get this error:
TypeError: Failed to execute 'createObjectURL' on 'URL': Overload resolution failed.
Here is the code of the NodeJS server, where I sent the file:
routerTrainer.post("/download-training", verifyJWT, async (req, res) => {
const { trainer_id, training_id } = req.body;
let training = await Training.findOne({
where: { id: training_id, trainer_id },
});
if (training) {
const filePath = fs.createReadStream(`${path}${dirname}${training.file_id}`);
filePath.pipe(res);
}
})
And here is the code of the ReactJS frontend with file-saver:
const downloadTraining = async (id) => {
const JWT = new ClassJWT();
const axiosReq = axios.create();
await JWT.checkJWT();
axiosReq
.post(`${serverPath}/download-training`, {
trainer_id: await JWT.getId(),
training_id: id,
token: JWT.getToken(),
})
.then((res) => {
saveAs(res, "title");
})
.catch((err) => console.log(err));
};
Anyone know how to fix it??