0

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.

How can I convert data base64 string to image file using JavaScript? Is there any JavaScript library that does this?

1 Answer 1

1

You may use Data URLs:

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

this also works in img-Tags:

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

To trigger this by pure JavaScript, maybe this could work. The back-end should behave like a DOM browser:

var content = "data:jpg/image;base64,/9j/4AAQSkZJR....";
var window = window.open(content, "Image");
window.focus()
Sign up to request clarification or add additional context in comments.

2 Comments

I want to convert data base64 string to a file and save it in the mobile device.
you need to trick the device to trigger a file download, maybe my Edit helps?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.