Created
February 23, 2021 05:38
-
-
Save Alfxjx/65a0fd9b3227f0af0ee5788a6b15903b to your computer and use it in GitHub Desktop.
Axios download file in blob type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const findFile = url => { | |
return axiosBase.get(`path/toUrl?url=${url}`, { | |
responseType: "blob" | |
}); | |
}; | |
findFile(url, name) { | |
findFile(url).then(res => { | |
const resUrl = window.URL.createObjectURL(new Blob([res.data])); | |
const link = document.createElement("a"); | |
link.style.display = "none"; | |
link.href = resUrl; | |
link.setAttribute("download", name); | |
document.body.appendChild(link); | |
link.click(); | |
document.body.removeChild(link); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment