Advertisement
Guest User

Untitled

a guest
Sep 4th, 2021
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const downloadTraining = async (id) => {
  2.   const fileReader = new FileReader();
  3.  
  4.   const JWT = new ClassJWT();
  5.   const axiosReq = axios.create();
  6.   await JWT.checkJWT();
  7.   axiosReq
  8.     .get(`${serverPath}/download-training`, {
  9.       headers: {
  10.         training_id: id,
  11.         token: JWT.getToken(),
  12.         responseType: "blob",
  13.       },
  14.     })
  15.     .then((response) => {
  16.       fileReader.readAsDataURL(response.data);
  17.     })
  18.     .catch((err) => console.log(err));
  19.  
  20.   fileReader.addEventListener("loadend", () => {
  21.     const blobString = fileReader.result;
  22.     const link = document.createElement("a");
  23.     link.href = blobString;
  24.     link.setAttribute("download", "file.pdf");
  25.     document.body.appendChild(link);
  26.     link.click();
  27.   });
  28. };
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement