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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Contributor
Posts: 38
Registered: ‎03-07-2012
My Device: Dev Alpha B, Playbook 16GB, Z10 LE
My Carrier: Bell Canada
Accepted Solution

How to read file returned by File Picker

I'm obviously going daft here but for the life of me I cannot figure out how to read in a text file returned by the File Picker.  I am currently getting the correct full path of the file from the File Picker but where do I go from there?  blackberry.io.file does not seem to exist in Blackberry 10 and I am confused as to how I would utilize the HTML5 File API starting from just a file path returned by the File Picker.

 

Can someone please spit out a quick and dirty example showing me the basics of reading in file data starting from a path returned by File Picker please?

 

Thanks very much,

DM

------------
"The shortest answer is doing." - Jacula Prudentum
My app: Cashalyst
Retired
Posts: 245
Registered: ‎09-21-2012
My Device: Q10
My Carrier: Virgin

Re: How to read file returned by File Picker

Sure if you have the path to the file then you are part way there. One thing to note. The file MUST be inside you bar(sandbox) OR you need to add the <rimSmiley Tongueermit>access_shared</rimSmiley Tongueermit>
and then the file can live in the shared folder on device.

 

Here is some code you can use to read a file. I poached it from our docs found here:https://developer.blackberry.com/html5/apis/blackberry.io.html

 

<script type="text/javascript">

function readFile() {
    // un-sandbox file system to access shared folder
    blackberry.io.sandbox = false;

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

    window.requestFileSystem(window.TEMPORARY, 1024 * 1024,
        function (fs) {
             // in order to access the shared folder,
             // config.xml must declare the "access_shared" permission
             // reference file by absolute path since file system is un-sandboxed
             fs.root.getFile(blackberry.io.sharedFolder + '/Documents/log.txt', {create: true},
                 function (fileEntry) {
                     fileEntry.file(function (file) {
                         var reader = new FileReader();

                         reader.onloadend = function (e) {
                             var txtArea = document.createElement('textarea');
                             txtArea.value = this.result;
                             document.body.appendChild(txtArea);
                         };

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

function errorHandler(e) {
    var msg = '';

    switch (e.code) {
    case FileError.QUOTA_EXCEEDED_ERR:
        msg = 'QUOTA_EXCEEDED_ERR';
        break;
    case FileError.NOT_FOUND_ERR:
        msg = 'NOT_FOUND_ERR';
        break;
    case FileError.SECURITY_ERR:
         msg = 'SECURITY_ERR';
         break;
    case FileError.INVALID_MODIFICATION_ERR:
         msg = 'INVALID_MODIFICATION_ERR';
         break;
    case FileError.INVALID_STATE_ERR:
         msg = 'INVALID_STATE_ERR';
         break;
    default:
         msg = 'Unknown Error';
        break;
    };

    console.log('Error: ' + msg);
}
</script>
@erikjohnzon
erjohnson@blackberry.com
Highlighted
Contributor
Posts: 38
Registered: ‎03-07-2012
My Device: Dev Alpha B, Playbook 16GB, Z10 LE
My Carrier: Bell Canada

Re: How to read file returned by File Picker

Excellent. Thank you very much for this. I obviously need to read the online docs a bit more thoroughly Smiley Happy

DM
------------
"The shortest answer is doing." - Jacula Prudentum
My app: Cashalyst