Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

New Contributor
Posts: 3
Registered: ‎06-30-2013
My Device: BlackBerry Z10
Accepted Solution

Failed to call LocalFileSystem in Black Berry Z10



I am developing and deploying an app in my BB Z10. I getting an error message - "Can't find variable - LocalFileSystem".


Below is the code where I calling the LocalFileSystem: 


window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
var fs = null;


$(document).ready(function() {
        document.addEventListener("webworksready", function(e) {
                          window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(filesystem) {
                                   fs = filesystem;
                           }, errorHandler);
        }, false);


I had study https://developer.blackberry.com/html5/apis/localfilesystem.html and https://developer.blackberry.com/html5/documentation/using_webworks_apis.html and follow those instruction but all APIs that begin with "HTML5" were failed to call (My app was worked well with others API like FileTransfer, IO etc).


Can someone please suggest how to resolve?





Kian Ping



Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10

Re: Failed to call LocalFileSystem in Black Berry Z10

Looks like you might be requesting a filesystem of zero size.  Try this:


window.webkitRequestFileSystem(window.TEMPORARY, 1024 * 1024, receivedFs, onFileError);


Where "receivedFs" would be some function like so:


function receivedFs(filesystem) {

    // Do something



and "onFileError" being the appropriate error callback function.


Hope that helps!

-_- zZZ
New Contributor
Posts: 3
Registered: ‎06-30-2013
My Device: BlackBerry Z10

Re: Failed to call LocalFileSystem in Black Berry Z10

Hi grahamzibar,


The purpose that I want to access file system is to retrieve directory of shared folder/downloads and check the existence of a pdf file

My strategic:

1) Obtain file system fs from window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(filesystem) { fs = file system; }, function(error){alert(error.message:smileywink:};

2) After that, check the existence of a pdf file by using html5 directory reader and for loop

var pdf_exist = false;

var directoryReader = fs.root.createReader();



     for(var i=0; i<entries.length; i++){

          if(FileEntry[i].name == "xxx.pdf"){

               pdf_exist = true;




},function(er){alert( er.message);});


3) Then, if pdf_exist = false, then download the pdf file; else open and view the pdf file;


Above strategic was worked well in android and iphone. I had tried blackberry.io.file.exists() but this function not supported in BB10.



Between, I had also tried this: window.webkitRequestFileSystem(window.TEMPORARY, 1024 * 1024, function(filesystem) { fs = file system; }, function(error){alert(error.message:smileywink:});. It return a null value (fs = null)


Any other way that can verify/check the existence of pdf file which located in file:///accounts/1000/shared/downloads/?


Thanks in advance.



Kian Ping



Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10

Re: Failed to call LocalFileSystem in Black Berry Z10

The below function worked perfectly for me on a Z10 running OS 10.1.  Let me know if this works for you too :smileyhappy:  You would need to wait for the webworks ready event and have all the necessary config.xml settings (such as the permission to access the shared directory as well as adding the blackberry.io feature).  Let me know if you have any more questions!


function checkPDF() {
    blackberry.io.sandbox = false;
    var hasPDF = false;
        1024 * 1024,
        function(fs) {
            console.log('harr', blackberry.io.sharedFolder + '/downloads');
                blackberry.io.sharedFolder + '/downloads',
                { create: false },
                function(folder) {
                    console.log('folder!!', folder.fullPath);
                        function(entries) {
                            console.log('ENTRIES:', entries); // CONSOLE SANITY CHECK :smileyhappy:
                            for (var i = 0; i < entries.length; i++) {
                                if (entries[i].name.indexOf('.pdf') != -1)
                                    hasPDF = true;
                            alert(hasPDF); // HERE'S YOUR ANSWER

-_- zZZ
New Contributor
Posts: 3
Registered: ‎06-30-2013
My Device: BlackBerry Z10

Re: Failed to call LocalFileSystem in Black Berry Z10



Yes,I found out the reason why I getting null value when I calling window.webkitRequestFileSystem. This is because I missed this 1 - blackberry.io.sandbox = false;


Now I able to obtain fs value and the value I obtained is filesystem:local:///temporary/ . But, now I facing another problem: HTML getDirectory() doesn't work - no trigger success callback, no getting error message, no pop up any exception.


Below is the code where I calling getDirectory():

    fs.root.getDirectory(blackberry.io.sharedFolder + "/downloads", {create: false},
        function (folder) {
            alert("downloads folder is found");
        function (error) {
            alert("error with getting directory.");


This 1 is config.xml

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
	version="" id="org.apache.cordova.example">


  <author href="http://www.fingertec.com" email="support@fingertec.com">
		FingerTec WorldWide

       FingerTec Mobile Application
  <license href="http://opensource.org/licenses/alphabetical">

  <preference name="permissions"                value="none"/>

  <!-- Customize your app and platform with the preference element. -->
  <preference name="phonegap-version"           value="2.9.0" />          <!-- all: current version of PhoneGap -->
  <preference name="orientation"                value="default" />        <!-- all: default means both landscape and portrait are enabled -->
  <preference name="target-device"              value="universal" />      <!-- all: possible values handset, tablet, or universal -->
  <preference name="fullscreen"                 value="true" />           <!-- all: hides the status bar at the top of the screen -->
  <preference name="disable-cursor"             value="false" />          <!-- blackberry: prevents a mouse-icon/cursor from being displayed on the app -->
  <!-- Cordova API -->
  <feature id="org.apache.cordova" required="true" version="1.0.0" />
  <feature id="blackberry.find" required="true" version="" />
  <feature id="blackberry.identity" required="true" version="" />
  <feature id="blackberry.identity.phone" required="true" version="" />
  <feature id="blackberry.pim.Address" required="true" version="" />
  <feature id="blackberry.pim.Contact" required="true" version="" />
  <feature id="blackberry.utils" required="true" version="" />
  <feature id="blackberry.io.dir" required="true" version="" />
  <feature id="blackberry.app" required="true" version="" />
  <feature id="blackberry.app.event" required="true" version="" />
  <feature id="blackberry.system.event" required="true" version=""/>
  <feature id="blackberry.widgetcache" required="true" version=""/>
  <feature id="blackberry.media.camera" />
  <feature id="blackberry.ui.dialog" />
  <feature id="blackberry.connection" />
  <feature id="blackberry.bbm.platform" />
  <feature id="blackberry.invoke.card" />
  <feature id="blackberry.pim.contacts" />
  <feature id="blackberry.ui.contextmenu" />
  <feature id="blackberry.system" required="true" version="" />
  <feature id="blackberry.io.file" required="true" version="" />
  <feature id="blackberry.io.filetransfer" required="true" version=""/>
  <feature id="blackberry.io" required="true" version=""/>
  <feature id="blackberry.invoke" required="true" version=""/>
  <feature id="blackberry.invoked" />
  <feature id="blackberry.push" />
  <feature id="blackberry.media.microphone" required="true" version=""/>
  <!-- Cordova API -->
  <access subdomains="true" uri="file:///accounts/" />  
  <access subdomains="true" uri="file:///accounts/1000/shared/downloads/" />  
  <!-- Expose access to all URIs, including the file and http protocols -->
  <access subdomains="true" uri="*" />

  <icon rim:hover="false" src="images/appicon.png" />
  <icon rim:hover="true" src="images/appicon.png" />

  <rim:loadingScreen backgroundColor="#CFCFCF"
    <rim:transitionEffect type="fadeOut" />

  <content src="local:///index.html"/>




I ...

1) had set the permission to access and declare the feature in config.xml and declare those needed plugin in plugins.xml

2) able to fires the webworks ready event and able to obtain file system

3) had un-sandbox the file system to access shared folder


Have I missed something out? Or which part I did wrong?



Kian Ping