Download file from dataURL

Download file from dataURL

BY 10 Feb 2015 Web Application Development

I have a web application with a Canvas element and I am required to save the image currently in the canvas to the Device at a preferred location.

I have obtained the dataURL on clicking the save button and trying to download the image.

var dataURL = canvas.toDataURL();
document.getElementById(“test”).setAttribute(“href”,dataURL);
document.getElementById(“test”).setAttribute(“download”,”image.png”);
document.getElementById(“test”).click();

I also tried

window.open(canvas.toDataURL,”tempimage.png”);

which works in browser but is not working in the app.

 

Any suggestions or solution on How to download as an image the content under canvas tag?

Written by