Question

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?

Was it helpful?

Solution

Crosswalk is a web runtime, it doesn't provide a download manager UI like what other browsers are doing, it should not be runtime's target. Crosswalk spawns the Android's selected download manager when user clicks a downloaded link, and it will launch the download manager or default browser to download resources.

If web developers want to download a file and save it to the device(native filesystem), I think Cordova download api should be a good choose now. Please see: https://cordova.apache.org/docs/en/3.0.0/cordova_file_file.md.html#FileTransfer Does it meet your requirement?

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top