强制下载base64图像 [英] force download base64 image

查看:104
本文介绍了强制下载base64图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从JS开始并不是我的优势之一。在过去的几天里,我一直在尝试编辑这个JS函数,以强制下载base64图像。单击下载按钮时,该功能的作用是打开一个新窗口,上面有图像。然后用户必须右键单击并保存图片。我正试图强制下载图像,而不是右键单击并另存为。

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’.

dataurl生成base4 png字符串(数据:image / jpeg; base64,/ 9j / 4AAQSkZJRgABAQAAAQABAAD / 2wBDAAEBAQEBAQEBAQ .........)

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.

欢迎所有建议。谢谢。

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)
}


推荐答案

最后!我得到了它的工作。对于任何面临同样问题的人,我在这里找到了一个功能 http://danml.com/download.html 会让你强行下载base64。

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.

这篇关于强制下载base64图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆