I'm developing javascript app for android platform using intel XDK to build apk file. I'm using Crosswalk for android build with checked An API to read, write and navigate file system hierarchies, based on the W3C File API option. I can easily open files but can not save them to device.
For saving I did use the following code (The code works well in desktop chrome browser):
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
</head>
<body>
<img id="img"/>
<script>
saveImg = function (img, fileName) {
var a = document.createElement('a');
a.setAttribute('href', img.src);
a.setAttribute("download", fileName);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};
$(document).ready(function () {
var img = document.getElementById('img');
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAASUlEQVRo3u3PAQ0AIAwDsIGC+TcLLkhOWgddSU6G a5udT4iIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIi8cQEjUgGTmE6z3QAAAABJRU5ErkJggg==";
img.onload = onload;
function onload(){
saveImg(img, 'savedImg');
};
});
</script>
</body>
</html>
My android device write: finished to download file and in the download folder appears file: png;base64,iVBORw0KGgoAAAA...6z3QAAAABJRU5ErkJggg==.bin. The file size is 0KB and also I've noted that the name of the file is exactly the base64 interpritation of the img that I was trying to save.
How to solve this problem and be able to save file?
And Crosswalk is planing to support native file system, maybe it will be landed on Crosswalk 6, I am not sure the exact date. After native file system is supported, web developers can use XmlHttpRequest API to download files and save it to device(native file system) directly through Crosswalk filesystem API instead of Cordova download api.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With