31 lines
716 B
JavaScript
31 lines
716 B
JavaScript
import axios from "axios";
|
|
|
|
export default function downloadAsBlob(data, name) {
|
|
// Create blob link to download
|
|
const url = window.URL.createObjectURL(
|
|
new Blob([data]),
|
|
);
|
|
console.log(url);
|
|
downloadInteral(url, name);
|
|
}
|
|
|
|
export async function downloadUrl(url, name){
|
|
let res = await axios.get(url, {responseType: "blob"});
|
|
downloadAsBlob(res.data, name);
|
|
}
|
|
|
|
function downloadInteral(url, name){
|
|
const link = document.createElement("a");
|
|
link.href = url;
|
|
link.download = name;
|
|
link.target = "_blank";
|
|
|
|
// Append to html link element page
|
|
document.body.appendChild(link);
|
|
|
|
// Start download
|
|
link.click();
|
|
|
|
// Clean up and remove the link
|
|
link.parentNode.removeChild(link);
|
|
} |