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
Posts: 26
Registered: ‎03-06-2012
My Device: playbook
My Carrier: 8298611647

Is there a way to handle files in the BB playbook?

Is there a way to handle files in the BB playbook?

Contributor
Posts: 15
Registered: ‎08-07-2011
My Device: Playbook
My Carrier: None

Re: Is there a way to handle files in the BB playbook?

New Developer
Posts: 26
Registered: ‎03-06-2012
My Device: playbook
My Carrier: 8298611647

Re: Is there a way to handle files in the BB playbook?

[ Edited ]

It dosent work, it say the blackberry.io is undefined.

 

i also added to the config.xml the features, but it dont work either.

 

<feature id="blackberry.app" required="true"/>
<feature id="blackberry.app.event" required="true"/>

Contributor
Posts: 15
Registered: ‎08-07-2011
My Device: Playbook
My Carrier: None

Re: Is there a way to handle files in the BB playbook?

[ Edited ]

I have this and it works:

 

   <rimSmiley Tongueermissions>
        <rimSmiley Tongueermit>access_shared</rimSmiley Tongueermit>
    </rimSmiley Tongueermissions>
 
  <feature id="blackberry.io.dir" required="true"/>
    <feature id="blackberry.io.file" required="true"/>

New Developer
Posts: 26
Registered: ‎03-06-2012
My Device: playbook
My Carrier: 8298611647

Re: Is there a way to handle files in the BB playbook?

[ Edited ]

Sorry, the blackberry.io shall be call locally, i was using a locahost for fast debug

New Developer
Posts: 26
Registered: ‎03-06-2012
My Device: playbook
My Carrier: 8298611647

Re: Is there a way to handle files in the BB playbook?

Now i have another problem, i can read the appDirs, and see all the available directories, i also can use listFiles to get every file in a know dir. 

 

I can use readFile, but it only send my callback function this

{ 'id' : '959c208f9caf7b9773c16...................'}

 

(maybe a GUID??)

an the path id gave.

I used the blackberry.utils.blobtoString function and it return a null object

Were's the mistake? can somebady give and example of a working app (the API documentation dont show how to read the files data, just the size)

Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: Is there a way to handle files in the BB playbook?

readFile takes a function and that function receives the path as a String and the file data as a Blob.

 

What file are you trying to open, and what OS are you trying it on?

 

What you are getting back doesn't seem to be what you should.

 

 

Tim Windsor
Open Source Technical Lead
New Developer
Posts: 26
Registered: ‎03-06-2012
My Device: playbook
My Carrier: 8298611647

Re: Is there a way to handle files in the BB playbook?

Im using OS 2 on a playbook. The file is a Zip or a Txt, none of em worked.

 

 

Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: Is there a way to handle files in the BB playbook?

I've got it working and I think you've got it working as well, or pretty close to it.

 

That id and value you see is for the Blob object itself. Call blackberry.utils.blobToString(blob) on that and you'll get the actual contents.

 

var dirs = blackberry.io.dir.appDirs;
var textFile = dirs.shared.documents.path + "/test.txt";
if (blackberry.io.file.exists(textFile)) {
  blackberry.io.file.readFile(textFile, onOpen);
}

function onOpen(path, data) {
  log("Opening ->" + path);
  log("Data");
  log(data);
  log("<hr>");
  log(blackberry.utils.blobToString(data));
  fileData = data;
}
	
function log(value) {
  document.getElementById('log').innerHTML += "<br>" +value; 
}

 Note that if you call blobToString on a binary file you may not get all the data into the String since there will be incompatible characters.

Tim Windsor
Open Source Technical Lead