About the invalid download of a tag (canvas)

has obtained a canvas, and then downloaded and saved it, but the result part cannot be downloaded.
the size of the picture is 4m, while it is said online that the href length of an is limited.
how to download

function aa(src,imgname){
    var alink=document.createElement("a");
    alink.href=src;
    alink.download=imgname;
    alink.click();
    alink.remove();
}
var url = canvas.toDataURL("image/png");
aa(url,"");
Dec.08,2021

it is recommended to use the toBlob method, which can convert canvas into Blob files, which is usually used in file uploads because it is binary and more back-end friendly.

Note that toBlob () is asynchronous, so there will be a callback

canvas.toBlob(function(blob) {
  var url = URL.createObjectURL(blob);
  a.href = data;
  a.download = 'bg.png';
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3654f-2b36b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3654f-2b36b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?