Skip to content

Instantly share code, notes, and snippets.

@Alfxjx
Created February 23, 2021 05:38
Show Gist options
  • Save Alfxjx/65a0fd9b3227f0af0ee5788a6b15903b to your computer and use it in GitHub Desktop.
Save Alfxjx/65a0fd9b3227f0af0ee5788a6b15903b to your computer and use it in GitHub Desktop.
Axios download file in blob type
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