I have an image encoded in base64 in a javascript variable : data:image/png;base64, base64 data
[EDIT] I need to save that file to disk without asking to the visitor to do a right click [/EDIT]
Is it possible ? How ?
Thanks in advance
Best regards
I have an image encoded in base64 in a javascript variable : data:image/png;base64, base64 data
[EDIT] I need to save that file to disk without asking to the visitor to do a right click [/EDIT]
Is it possible ? How ?
Thanks in advance
Best regards
The accepted solution seems to have a limitation for large data. If you're running into this (instead of the downloaded file's name, I see "download" and "Failed - Network error" in Chrome), here's what I did in order to download a 2mb file:
const blob = await (await fetch(document.getElementById('canvasID').toDataURL())).blob();
const file = new File([blob], {type:"image/png", lastModified: new Date()});
var a = document.createElement('a');
a.href = window.URL.createObjectURL(file);
a.download = 'image.png';
a.click();