I have a script that's broken and its currently trying to upload form contents to imgbb. I dont want that, instead i want it to save the canvas contents to a jpg file locally on visitors web browser. How do i do this? Here's the current code:
const formData = new FormData();
formData.append("image", canvas.toDataURL().split(',')[1])
var req = new XMLHttpRequest()
req.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
response = JSON.parse(this.response)
console.log(response)
url = response.data.image.url
$('#Loading').hide();
$('#URL').val(url).fadeIn();
}
}
req.open("POST", 'https://api.imgbb.com/1/upload?key=xxxxxxxxxxxxxxxxxxxxxxxxxx', true)
req.send(formData)
},
Ive tried the tutorial at How To Save Canvas As An Image With canvas.toDataURL()? but it doesnt work and also is incompatible with many browsers.
Everything i try doesnt work. Ive been going insane for the last day.