Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const downloadTraining = async (id) => {
- const fileReader = new FileReader();
- const JWT = new ClassJWT();
- const axiosReq = axios.create();
- await JWT.checkJWT();
- axiosReq
- .get(`${serverPath}/download-training`, {
- headers: {
- training_id: id,
- token: JWT.getToken(),
- responseType: "blob",
- },
- })
- .then((response) => {
- fileReader.readAsDataURL(response.data);
- })
- .catch((err) => console.log(err));
- fileReader.addEventListener("loadend", () => {
- const blobString = fileReader.result;
- const link = document.createElement("a");
- link.href = blobString;
- link.setAttribute("download", "file.pdf");
- document.body.appendChild(link);
- link.click();
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement