Search code examples
cordovablackberry-webworks

How do I access data stored using the filesystem API on BlackBerry WebWorks inside HTML?


If I save a file using the filesystem API, and I get the URL of the file, it gives me a "filesystem:local://" location, which I can't whitelist and the system tells me the URL is invalid. How do I embed these files into my HTML?


Solution

  • First you need to install the io webworks plugin. There is a Cordova version on GitHub. Just download the zip file and run this command:

    cordova plugin add /path/to/zip/plugin/com.blackberry.io
    

    Then in your config.xml, you need to add this:

    <access origin="file:///accounts" subdomains="true"/>
    

    Now, when you call FileEntry.getURL(), you'll need to mutate the result like so:

    var regex = new RegExp('^filesystem:local:///([^/]+)/(.*)$');
    var url = FileEntry.getURL();
    url = url.replace(regex,'file://'+blackberry.io.home+'/webviews/webfs/$1/local__0/$2');
    

    The resulting URL will look something like so:

    file:///accounts/1000/appdata/your.app.id.testDev_ting_f95ecbe/data/webviews/webfs/persistent/local__0/your/file
    

    Using that URL, you can then embed the contents into your HTML:

    <img src="file:///accounts/1000/appdata/your.app.id.testDev_ting_f95ecbe/data/webviews/webfs/persistent/local__0/myimg.png">
    

    Hope that helps!