我正在尝试将base64保存为字符串作为Image。我使用下面的Javascript代码
<html>
<head>
<title>JS Download base64 Image</title>
<script type="text/javascript">
function DownloadImageAndSave(){
var base64string = "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCABkAfQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD3+iiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigArhfippOs3nhj+1NC1e5sL/AEcteokTYWcKvKsO/GcZyDyCOa7qsLxH4v8ADvheANrup29qJF+WJ/mdxz0QZJHHpigDlf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ccfHfiTxTJ9m8F+G54oWH/ACFtYjMMCj1ROr/5yK0/Dnw9h0/Uv7c8QX8mva+Tlbu5TCQD+7FH0Qe4/DHSgDJmPjL4iwGOFZfCvh2UcySDN9cp7KDiIEfj9QcV3Gg+H9M8M6TFpmk2qW9rGOi9WPdmPUk+prTooAK8k+A91C+leJrZF/eR6xJIWAOCrKAvX/cP516nfrcPp10lm4S6aJxCx6B8Hae/fFeVfs/aLeaX4W1ae+ingmmvzGYZY9uPLUAnnk5YkH/doAseKvhNqF3Jfr4W15tNsdXkLalYT/PAckEvGAPlbI6d+mQOK9M06zXTtLtLFZGkW2hSEO/3mCqBk+/FWaKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigArntb8C+FvEbO+q6FZXErnLTeXslb6uuG7etFFAHOH4M+GlEiw3mtwI33Uj1FwIxjGFzn9c1zV/oWo6f4ys/DUHjPxQLGdCWZr4GVenCvsyKKKAOpi+DXhFju1NNR1eTJPmX99I5yf90qP0ro9N8FeF9IaN7Dw/psEkZBSVbZN4I77iM5/GiigDdooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//Z";
var img = new Blob([base64string],{type: 'image/png'});
var url = URL.createObjectURL(img);
url.download = 'signature.png';
}
</script>
<form name="testJsImage" id="testJsImage" />
<input type="button" name="buttonDownload" value="DownLoad Image" onclick="DownloadImageAndSave();" />
</form>
</head>
</html>
它应该转换为base 64并下载,但是相反,我从Javascript控制台收到此错误。
Uncaught TypeError: Failed to construct 'Blob': The provided value cannot be converted to a sequence.
at DownloadImageAndSave (JsDownloadTest.htm:9)
at HTMLInputElement.onclick (JsDownloadTest.htm:15)
我似乎缺少什么吗?
修改
我将字节放入数组中,更糟糕的是,base64映像无法下载。