简体   繁体   English

JavaScript-将数据库base64字符串转换为图像

[英]JavaScript - convert data base64 string to image

I am making a mobile app using PhoneGap and I want to convert data base64 string to a file and save it in the mobile device. 我正在使用PhoneGap制作移动应用程序,我想将base64字符串转换为文件并将其保存在移动设备中。

How can I convert data base64 string to image file using JavaScript? 如何使用JavaScript将base64字符串转换为图像文件? Is there any JavaScript library that does this? 有没有执行此操作的JavaScript库?

You may use Data URLs: 您可以使用数据网址:

<a href="data:jpg/image;base64,/9j/4AAQSkZJR...." target="_blank">

this also works in img-Tags: 这也适用于img-Tags:

<img src="data:jpg/image;base64,/9j/4AAQSkZJR...." />

To trigger this by pure JavaScript, maybe this could work. 要通过纯JavaScript触发此操作,也许可以起作用。 The back-end should behave like a DOM browser: 后端的行为应类似于DOM浏览器:

var content = "data:jpg/image;base64,/9j/4AAQSkZJR....";
var window = window.open(content, "Image");
window.focus()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM