Welcome!

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

Reply
New Developer
gstevenson
Posts: 17
Registered: ‎12-05-2011
My Device: BlackBerry 10 Dev Alpha
Accepted Solution

Timeout period of window.webkitRequestFileSystem?

Hi folks,

 

My application has a function which checks if there is a file on disk, as below:

 

        ItemHasReceipt: function (item, callback) {

            console.log('ItemHasReceipt:');
            console.log(item);

                blackberry.io.sandbox = false;

                window.webkitRequestFileSystem(window.PERSISTENT, 0, function (fs) {

                    var filePath = item.ReceiptPath;

                    console.log('trying to get ' + filePath);

                    fs.root.getFile(filePath, {},
                        function (entry) {
                            callback(item.ExpenseID, true);
                        },
                        function (e) {
                            callback(item.ExpenseID, false);
                        });
                    },

                    function (e) {
                        console.log('webKitRequestFileSystemError');
                        console.log(e);
                    }
                );
        
        }

The callback method is below:

 

ItemHasReceiptCallback: function (expenseid, hasReceipt) {

   console.log('ItemHasReceipt(' + expenseid + ', ' + hasReceipt + ')');

}

 If I call the function just once, it's fine and my callback gets hit. If I call it twice however, I only get as far as the 'trying to get xx' console log, I never seem to make it inside the webkitRequestFileSystem. My console only shows:

 

ItemHasReceipt:
ExpenseItem {ExpenseID: 1, OtherDetails: "Item with a receipt", Reason: Reason, ReasonID: 0, Total: 5…}

ItemHasReceipt: 
ExpenseItem {ExpenseID: 3, OtherDetails: "Item with no receipt", Reason: Reason, ReasonID: 506, Total: 3…}

trying to get /accounts/1000/removable/sdcard/camera/IMG_00000088.jpg 
ItemHasReceipt(3, true) 

 Is there a known issue with multiple accesses to the file system - or should I be doing something differently..?

 

Cheers,

 

G

BlackBerry Development Advisor
bryanhiggins
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3

Re: Timeout period of window.webkitRequestFileSystem?

Hi,

 

It would be more efficient to call webkitRequestFileSystem only once and keep a reference to fs.root.

 

That said you should be able to make multiple calls without issue. Could you add an error handler to to see what's going on there?

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
New Developer
gstevenson
Posts: 17
Registered: ‎12-05-2011
My Device: BlackBerry 10 Dev Alpha

Re: Timeout period of window.webkitRequestFileSystem?

Hi Bryan,

 

Thanks for the response.

 

I do have an error handler; the indentation was obviously just not showing it very well after I copy/pasted it. See below:

 

                window.webkitRequestFileSystem(
                    window.PERSISTENT,
                    0,
                    function (fs) {

                        var filePath = expense.ReceiptPath;

                        console.log('trying to get ' + filePath);

                        fs.root.getFile(filePath, {},
                            function (entry) {
                                callback(expense.ExpenseID, true);
                            },
                            function (e) {
                                callback(expense.ExpenseID, false);
                            });
                    },
                    function (e) {
                        console.log('webKitRequestFileSystemError');
                        console.log(e);
                    }
                 );

I never actually get any output from this log, though.

BlackBerry Development Advisor
bryanhiggins
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3

Re: Timeout period of window.webkitRequestFileSystem?

Ok, thanks - I missed that

 

I just tested out multiple calls to webkitRequestFileSystem and it works fine in both sandboxed and unsandboxed environments.

 

It's difficult to say if there is an issue without seeing the full app. If you can boil this down to a small sample app which demonstrates the issue, we can look into it. Also let us know what OS build you are using.

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
New Developer
gstevenson
Posts: 17
Registered: ‎12-05-2011
My Device: BlackBerry 10 Dev Alpha

Re: Timeout period of window.webkitRequestFileSystem?

Thanks for your help Bryan. I'm just throwing together a small dummy app using some of my code now.
New Developer
gstevenson
Posts: 17
Registered: ‎12-05-2011
My Device: BlackBerry 10 Dev Alpha

Re: Timeout period of window.webkitRequestFileSystem?

Bryan, I've PM'd you with a link to a .zip.

BlackBerry Development Advisor
bryanhiggins
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3

Re: Timeout period of window.webkitRequestFileSystem?

Here is some code that reproduces the issue:

 

function requestFSMultiple(count) {
    var i,
        log = function () { console.log(arguments); }
    for (i = 0; i < count; i++) {
        blackberry.io.sandbox = false;
        window.webkitRequestFileSystem(1, 0, log, log);   
     }
}

 

To fix, move blackberry.io.sandbox = false before the loop:

 

function requestFSMultiple(count) {
    var i,
        log = function () { console.log(arguments); }
    blackberry.io.sandbox = false;
    for (i = 0; i < count; i++) {
        window.webkitRequestFileSystem(1, 0, log, log);
     }
}

We will investigate the root cause, but you should really only set it once. 

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
New Developer
gstevenson
Posts: 17
Registered: ‎12-05-2011
My Device: BlackBerry 10 Dev Alpha

Re: Timeout period of window.webkitRequestFileSystem?

Brilliant! My blackberry.io.sandbox wasn't actually in a loop but it was inside my function that got called multiple times, so same effect I suppose. I've moved it outside of the function and now I'm working. 

 

Thanks again Bryan.

New Developer
gstevenson
Posts: 17
Registered: ‎12-05-2011
My Device: BlackBerry 10 Dev Alpha

Re: Timeout period of window.webkitRequestFileSystem?

Just another quick question with regards to the above.

 

How long and under what circumstances does the 'sandbox' option persist? If I set it in page1.html and then navigate to somewhereelse.html would I need to set it again on somewhereelse.html if I wanted file system access there, or is it enough to simply do it once per app launch?

BlackBerry Development Advisor
bryanhiggins
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3

Re: Timeout period of window.webkitRequestFileSystem?

Once per app launch

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins