I'm using javascript to create a canvas drawing on my webpage and then convert it into a base64 image format. After that, I encode the URL of the image to obtain an encoded URL. I came across a post where it was mentioned that using window.location.href on the encoded string can help in downloading the image. I tried using options like window.location.href = img and window.open(img, 'download'), but I keep getting the error message. Can someone please assist me? My main goal is to download the canvas drawing as an image to the server.
Post : Download image which is src attribute (base64)
ERROR : The length of the URL for this request exceeds the configured maxUrlLength value.
<script type="text/javascript">
function loaded() {
var signature = new ns.SignatureControl({ containerId: 'container', callback: function () {
}
});
signature.init();
}
window.addEventListener('DOMContentLoaded', loaded, false);
function to_image() {
var canvas = document.getElementById("signatureCanvas");
document.getElementById("theimage").src = canvas.toDataURL();
var pngData = canvas.toDataURL("image/png");
var img = base64_encode(canvas.toDataURL("image/png"))
//window.location.href = img
//window.open(img, 'download');
}
function base64_encode(data) {
// Implementation of base64_encode function
}
Thank you for the helpful edit and response!