-
Notifications
You must be signed in to change notification settings - Fork 0
WorkingWithFiles
14paxton edited this page Feb 13, 2023
·
2 revisions
const formV = document.querySelector("input");
const btn = document.querySelector("button");
btn.addEventListener("click" , (e)=>{
e.preventDefault();
filefetch(formV.value);
})
function filefetch(url){
fetch(url)
.then(resp => resp.blob())
.then(file => {
let tURL = URL.createObjectURL(file);
let aTag = document.createElement("a");
aTag.href = tURL;
aTag.download = "file name";
document.body.appendChild(aTag);
aTag.click();
aTag.remove();
URL.revokeObjectURL(tURL);
})
}