Nam Pham
Nam Pham

Reputation: 1224

Crosswalk crashes with cordova-plugin-file when read file larger than 20MB

I'm using cordova-plugin-file to read my mp3 file with the readAsArrayBuffer method. It works perfect with a file less than 20mb, but with a larger file it causes the app to crash with this error. (I'm using crosswalk browser)

E/chromium( 3330): [ERROR:simple_index_file.cc(223)] Failed to write the temporary index file E/chromium( 3330): [ERROR:runtime_javascript_dialog_manager.cc(69)] Not implemented reached in virtual void xwalk::RuntimeJavaScriptDialogManager::ResetDialogState(content::WebContents*)

I'm so confused with what the problem is. Does the problem come from xwalk or cordova-plugin-file? Please help me because this plugin can only read file smaller than 20mb size.

Upvotes: 2

Views: 913

Answers (1)

Nam Pham
Nam Pham

Reputation: 1224

I found a solution for this bug. I think Cordova-plugin-file can't send large amount of data from native to javascript. So I try to research from Crosswalk Browser API and very happy to see that they support File API. It can get access directly to Android file system through virtual root like : EXTERNAL, CACHEDIR, DOWNLOADS, ... Here is the trick to read any big file with Crosswalk:

function readFileAsArrayBuffer(storage, path, file) {
    xwalk.experimental.native_file_system.requestNativeFileSystem(storage,
    function (fs) {
       fs.root.getFile(storage + "/" + path + file, {create: false}, function (entry) {
           entry.file(function (file) {
                reader = new FileReader();
                reader.onloadend = function (data) {
                   //Data after read.
                };
                  reader.readAsArrayBuffer(file);
                },
            },
            function (e) {
              console.error("2-" + JSON.stringify(e))
            });
        },
        function (e) {
          console.error("3-" + JSON.stringify(e));
        });
}
//test
readFileAsArrayBuffer("EXTERNAL", "downloads/folder/", "file.mp3");

Upvotes: 1

Related Questions