I'm trying to create a download button on my personal website for people to download my docx resume, but had some issues.
first i did it with simple href link thingy like
<a href="xxx.docx" download><button>download my resume</button></a>
but didn't work.
then i tried axois way, creating a button with the click action bind to the downloadFile(){} method, didn't work, coming with the error
GET
http://localhost:8080/assets/assets/imgs/cv_eudora.docx
404 (Not Found)Uncaught (in promise) Error: Request failed with status code 404 at createError (createError.js?2d83:16) at settle (settle.js?467f:17) at XMLHttpRequest.handleLoad (xhr.js?b50d:59)
I think it's because the url part in the downloadFile(){} function that's not stated properly, but don't know the right way to write the path in vue. The path itself should be right because it even had the automatic hint options all the way when i did it.
<button @click="downloadFile()">download my resume</button>
downloadFile() {
axios({
url: "../assets/imgs/cv_eudora.docx",
method: "GET",
responseType: "blob" // important
}).then(response => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement("a");
link.href = url;
link.setAttribute("download", "eudoraCV.docx"); //or any other extension
document.body.appendChild(link);
link.click();
});
}