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
BlackBerry Development Advisor
twindsor
Posts: 822
Registered: ‎07-15-2008
My Device: Z10
My Carrier: Bell

Re: Hi Due North, The sharedFolder variable does not point...

Just to clarify that last point, local:/// is the path to access inside the Application's BAR file. So if you packaged an image in your source folder at "/images/image.png" and then build this into the BAR, you can reference it at "local:///images/image.png".

 

The rest of the file system on the actual device is sandboxed. Each application has it's own space to store data and only it has access to this space. By default, that is the area that you access through the HTML5 filesystem API. You can also access the shared space outside the sandbox, by setting that blackberry.io.sandbox property to false. The blackberry.io.sharedFolder path uses your application's very own pathway to the shared folder, and needs to be used instead of trying to use a direct file path.

Tim Windsor
Application Development Advisor II
Please use plain text.
Developer
DueNorth
Posts: 135
Registered: ‎09-25-2012
My Device: Dev Alpha
My Carrier: Rogers

Re: Hi Due North, The sharedFolder variable does not point...

So if I want to check if the file exists in the local path, I would need to use IO and use:

 

function readFile() {
    blackberry.io.sandbox = false;

    window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;

    window.requestFileSystem(window.TEMPORARY, 1024 * 1024,
        function (fs) {
             fs.root.getFile('local:///images/image.png', {create: false},
                 function (fileEntry) {
                     fileEntry.file(function (file) {
                         var reader = new FileReader();

                         reader.onloadend = function (e) {
    				console.log(this.result)
                         };

                         reader.readAsText(file);
                    }, errorHandler);
                 }, errorHandler);
        });
}

 

and then use the error handler to check to see if the file exists. Seems like a lot of code just to check if a file exists.

 

I haven't tested the above yet but it seems like a big work around for blackberry.io.file.exists .

Please use plain text.
BlackBerry Development Advisor
twindsor
Posts: 822
Registered: ‎07-15-2008
My Device: Z10
My Carrier: Bell

Re: Hi Due North, The sharedFolder variable does not point...

It depends on your perspective. This is more code, but it's also standards compliant and cross platform (except for a quick check like if (blackberry && blackberry.io) before the call to blackberry.io.sandbox).

 

This means that you are able to use an HTML5 framework or other libraries and you aren't dependent on AIR extensions anymore.

 

You can easily write this in a nice little cross platform library that you could add whenever you needed, and which could simplify the interface down to filesystem.exists(url).

Tim Windsor
Application Development Advisor II
Please use plain text.
Developer
asiayeah
Posts: 118
Registered: ‎11-05-2011
My Device: Z10, Bold 9900
My Carrier: Smartone

Re: Hi Due North, The sharedFolder variable does not point...


twindsor wrote:

It depends on your perspective. This is more code, but it's also standards compliant and cross platform (except for a quick check like if (blackberry && blackberry.io) before the call to blackberry.io.sandbox).

 

This means that you are able to use an HTML5 framework or other libraries and you aren't dependent on AIR extensions anymore.

 

You can easily write this in a nice little cross platform library that you could add whenever you needed, and which could simplify the interface down to filesystem.exists(url).


I wish to see existing WebWorks File API (e.g. blackberry.io.dir.exists) available for BB 10. It would simplify porting PlayBook and BlackBerry WebWorks app to bb10. The HTML 5 versions are also async, unlike existing WebWorks File API which are synchronous. It is not a trivial task to migrate existing codes to HTML 5 File API unfortunately.

Please use plain text.
Developer
DueNorth
Posts: 135
Registered: ‎09-25-2012
My Device: Dev Alpha
My Carrier: Rogers

Re: Hi Due North, The sharedFolder variable does not point...

[ Edited ]

Sorry for the delay in replying, was working on the Port-a-thon. :-)

 

The above code would get a NOT_FOUND_ERR. I tried multiple paths using Local and it just won't find it.

 

'local:///images/image.png'

'local:///image.png'

'local://image.png'

 

I don't think the HTML5 FileSystem and "local://" works well together. I think it was meant for people to use for temporary storage when images get captured, transfered, etc. to be later throw away (or kept). It wasn't meant to read from an internal BAR or file system. This would need more of a system API to check if file exists. I believe this is mainly because of security. Imagine how bad it would be if Javascript can run (or check for) files on the local file system?

 

I am about to give up on this, and use some sort of database solution. :-(

Please use plain text.
BlackBerry Development Advisor
twindsor
Posts: 822
Registered: ‎07-15-2008
My Device: Z10
My Carrier: Bell

Re: Hi Due North, The sharedFolder variable does not point...

You may have given up already, but a colleague of mine has written a wrapper for the HTML5 File APIs that make them a lot better to work with.

 

https://github.com/grahamzibar/BlackBerry-Library#filemanager

Tim Windsor
Application Development Advisor II
Please use plain text.
Developer
DueNorth
Posts: 135
Registered: ‎09-25-2012
My Device: Dev Alpha
My Carrier: Rogers

Re: Hi Due North, The sharedFolder variable does not point...

Yeah, I rewrote that section. I have saved your link as a favorite to revisit when I work on my next app. Thanks Tim for following up! 

Please use plain text.