Simple question, how to make this code work? It's in the state where CORS is the problem. And actually, I don't think the code looks like this.
Note that the response should return a blob (Because I to save the file to the database).
<input type="url">
let input = document.querySelector('input');
input.addEventListener('change', () => {
let xhttp = new XMLHttpRequest();
xhttp.open('GET', input.value, true);
xhttp.responseType = 'blob';
xhttp.send();
xhttp.addEventListener('readystatechange', () => {
if(xhttp.readyState == 4 && xhttp.status == 200){
let reader = new FileReader();
reader.readAsDataURL(xhttp.response);
reader.onload = () => {
document.body.style.backgroundImage = `url(${event.target.result})`;
}
}
});
});
Thank you
Edit: I already found the answer here