Application I'm working on
I'm working on a Cordova 2.2.0 application that's used in a slow-(or none)internet environment.
It gains data from a CMS system.
this data (JSON) is stored locally on the mobile device using Cordova's filesystem. This provides data for moments this application doesn't have access to the internet.
Problem
Data storage and recovery using Cordova's filesystem is working fine. The data stored to the filesystem is in JSON. After parsing this JSON it is converted to HTML. Problem is that this gives me IMG tags with an external source like this:
<img src="http://www.SomeUrl.com/Images/SomeImage.jpg" id="someImage" />
I want to load this Image and convert it to base64 using JavaScript. If this is possible, I will be able to write it to the local filesystem for offline use. Something like this:
var imageFromURLToBase64(imageURL){
"use strict";
var image = doSomethingWithUrl(imageURL),
base64 = "";
//CONVERT IMAGE TO BASE64 HERE
return base64;
};
var imageUrl = $("#someImage").attr("src"),
base64 = imageFromURLToBase64(imageUrl);
//Store base64 image to local filesystem
help is highly appreciated!
P.S. cross origin requests are enabled on this server!
Alternatives
If there's some better alternative for caching images out there, I'd be happy to hear about it. I've read a little bit about HTML cache manifest here, but I don't know if this suits my problem.
Duplicate question
There are more people dealing with this problem, answers to those questions didn't solve my problem. this answer or this answer don't tell me what's the best way to cache my images for a phonegap application. I wondered if there where better ways to encode images to base64, but my real question is: "What's the best way to store/cache my images for a phonegap application?"