0

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??

Gonsa02
  • 193
  • 7
  • Does this answer your question? [Downloading a file from a Node.JS API REST (express) with React.JS (Axios Get)](https://stackoverflow.com/questions/64811867/downloading-a-file-from-a-node-js-api-rest-express-with-react-js-axios-get) – Elikill58 Aug 31 '21 at 08:27

0 Answers0