Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force download base64 image

To start with JS isn’t one of my strengths. I’ve been trying for the past couple of days to edit this JS function to make it force download base64 image. What the function does, when the download button is clicked, is open a new window with the image on it. The user then has to right click and save the picture. I’m trying to force download the image instead of right click and ‘save as’.

The dataurl produce base4 png string (data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQ………)

i tried using as it was suggested in another thread but that didn't work.

All suggestions are welcomed. Thanks.

savePaint: function() {
            var self = this;

            dataURL = self.context.canvas.toDataURL();

            var cntnt = $("<p class='dialogHeader'>Please right click and select 'Save Image As' option. Click here to Return</p>           <img id='PrintImage' src=" + dataURL + ">");
            self.newSavedImage.html(cntnt);

            self.showPopup(self.newSavedImage, self.canvasWidth, self.canvasHeight)
}
like image 799
user2334436 Avatar asked Dec 06 '14 03:12

user2334436


1 Answers

Finally! I got it to work. For anyone facing the same problem I found a function here http://danml.com/download.html that will let you force download the base64.

like image 129
user2334436 Avatar answered Oct 12 '22 18:10

user2334436