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
Developer
Posts: 119
Registered: ‎05-27-2010
My Device: 9900
My Carrier: Vodafone NL

Access to the FileSystem files from HTML, CSS and Javascript.

I've been able to succesfully use the HTML5 File API's to read and write files to the HTML5 Filesystem.

 

But I've not been able to access the files using the ajax calls from bbUI.js.

 

The case is as follows:

 

blackberry.io.sandbox = false; //getting access to more files.
window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem( window.PERSISTENT, 5*1024*1024,initFS, errorHandler);

function initFS(fs) {
        console.log("Welcome to Filesystem! It's showtime :)"); // Just to check if everything is OK :)
        // place the functions you will learn bellow here
        fileName = blackberry.io.home +'/fotobericht.html'; //let's use the home folder now, also tried blackberry.io.sharedFolder
        fs.root.getFile( fileName, {create: true}, function(fileEntry) {
                // Create a FileWriter object for our FileEntry.
                console.log ('setting up the writer');
                fileEntry.createWriter(function(fileWriter) {
                
                fileWriter.onwrite = function(e) {
                    console.log('Write completed: ' + fileName);
                    console.log('file written: ' + fileEntry.name + " Path: " + fileEntry.fullPath + " URL: " + fileEntry.toURL() );
                    bb.pushScreen( fileEntry.toURL(), 'fotobericht');
                };

                fileWriter.onerror = function(e) {
                    console.log('Write failed: ' + e.toString());
                };

                img_screen = '<div style="background-color: #202020" data-bb-type="screen"><div data-bb-type="title" data-bb-caption="Fotobericht"></div>Hello World';
                img_screen += '<div data-bb-type="action-bar" data-bb-back-caption="Back"></div></div>';

                var blob = new Blob([img_screen], {type: 'text/plain'});
                console.log ('writing the file' + blob);
                fileWriter.write(blob);
                console.log ('blob blobbed?');

                
                }, errorHandler );

            }, errorHandler );

            
    };
 
 function errorHandler(err) {
            var msg = 'An error occured: ';
            
        switch (err.code) { 
            case FileError.NOT_FOUND_ERR: 
            msg += 'File or directory not found'; 
            break;
 
            case FileError.NOT_READABLE_ERR: 
            msg += 'File or directory not readable'; 
            break;
 
            case FileError.PATH_EXISTS_ERR: 
            msg += 'File or directory already exists'; 
            break;
 
            case FileError.TYPE_MISMATCH_ERR: 
            msg += 'Invalid filetype'; 
            break;
 
            default:
            msg += 'Unknown Error'; 
            break;
    };
 
    console.log(msg);
    };

 

The error produced is:

Access to "filesystem:local:///persistent/accounts/1000/appdata/<app.package.name>.testDev_rpg_XXXxxXxxxx_/data/fotobericht.html"

not allowed

[OK]

 

So how else could we access files stored in the HTML5 file system from XHR requests. HTML / CSS / Javascript ?

 

I want to be able to create pages on the fly for bbUI and push those to make my apps more versatile and dynamic.

 

Is there another path to the data path in WebWorks, that might work ?

 

Any suggestions ?

@reumerd-- @BBDevGroupNL -- about me
If you like it, LIKE it ;-) ----- If it's solved, press solved ! --- If you solved it yourself, please let us know! We might have the same problem!
Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Access to the FileSystem files from HTML, CSS and Javascript.

Hi there,

 

Could you try adding this to your config.xml:

 

<access uri="file:///accounts" subdomains=”true” />

And modifying the prefix of the path to:

 

file:///accounts/1000/appdata/<app.package.name>.testDev_rpg_XXXxxXxxxx_/data/fotobericht.htm

Alternatively, dropping the protocol completely may be it:

 

/accounts/1000/appdata/<app.package.name>.testDev_rpg_XXXxxXxxxx_/data/fotobericht.htm

Protocols and paths are still something I'm trying to wrap my head around as well, but the two approaches above have led to succes in the past in my testing.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Access to the FileSystem files from HTML, CSS and Javascript.

Another option is to try white-listing that URL directly.

<access uri="filesystem:local:///persistent/" subdomains=”true” />

But admittedly, that looks...odd.

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Developer
Posts: 119
Registered: ‎05-27-2010
My Device: 9900
My Carrier: Vodafone NL

Re: Access to the FileSystem files from HTML, CSS and Javascript.

Yes, I noticed that in some config.xml's today, hadn't tried it yet, but will give it a go later on.
@reumerd-- @BBDevGroupNL -- about me
If you like it, LIKE it ;-) ----- If it's solved, press solved ! --- If you solved it yourself, please let us know! We might have the same problem!
New Member
Posts: 1
Registered: ‎01-20-2014
My Device: N/A
My Carrier: N/A

Re: Access to the FileSystem files from HTML, CSS and Javascript.

I had this problem and was able to solve it using this thread. I went ahead and created a Stack Overflow Q/A will more detailed steps.

 

Relevant Stack Overflow