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
d_source
Posts: 116
Registered: ‎03-08-2011
My Device: Not Specified

Re: ReadFile and data manipulation

In this example, you are opening a file and then resaving it. What if you are saving a file for the first time?

 

I tried the script above in ripple and it doesn't work. Not really sure how ripple is supposed to be able to handle it. I will try it on the Playbook to see what happens there.

BlackBerry Development Advisor
twindsor
Posts: 832
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: ReadFile and data manipulation

saveFile just takes a path and a Blob, you can get a Blob from a String or a from a file. 

Tim Windsor
Open Source Technical Lead
Developer
d_source
Posts: 116
Registered: ‎03-08-2011
My Device: Not Specified

Re: ReadFile and data manipulation

Instead of hijacking this thread, I created a new one on my problems with the saveFile here if you can have a look please: http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/blackberry-io-file-saveFile-not-...

 

TY

BlackBerry Employee
jepal
Posts: 1
Registered: ‎04-22-2013
My Device: Q10

Re: ReadFile and data manipulation

How canthis be done in BB10? I want to read a file and display it line by line.

BlackBerry Development Advisor
twindsor
Posts: 832
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: ReadFile and data manipulation

There's a sample on this page that does pretty much that:

https://developer.blackberry.com/html5/apis/blackberry.io.html

Tim Windsor
Open Source Technical Lead
New Developer
rtholmes
Posts: 30
Registered: ‎04-21-2011
My Device: Playbook

Re: ReadFile and data manipulation

Hi Tim,

 

That sample is great, but it doesn't work if you have a full path (e.g., like you would get in info.uri returned by an invocation event). E.g., if I tap on a file that invokes my app from the file manager I might get:

 

file:///accounts/1000/invoke/org.ulti.dev.mobile.gpstracker.share/xa00000000002a8/retrace_2014-07-11_09-59.gpx

 whereas if I clicked on a file in the web browser (after it has downloaded) I might get:

file:///accounts/1000/shared/downloads/fells_loop.gpx 

 In both cases, using the snippet on the blackberry.io doc pages does not work, the result is always a call to the error handler with the code 'NOT_FOUND_ERR'. The only line I have changed compared to the sample is:

fs.root.getFile(blackberry.io.sharedFolder + '/Documents/log.txt', {create: true}

 to now be:

fs.root.getFile(invokeFName, {create: false},

If I munge the invokeFName coming from invoke (before the fs.root.getFile call):

invokeFName = blackberry.io.sharedFolder+invokeFName.replace('file:///accounts/1000/shared','');

Then I can read files when they are tapped in the browser or the file manager, but not when they are tapped on an attacment in the hub; also, munging the file name like this seems like a hack (and prone to fail if the 1000 is ever some other number).

 

Any ideas how we can read files URIs provided by invoke without hacky munging (mainly without having to get blackberry.io.sharedFolder involved)? (note: access_shared is on and my app is able to write / delete its own files already). 

 

New Developer
rtholmes
Posts: 30
Registered: ‎04-21-2011
My Device: Playbook

Re: ReadFile and data manipulation

Sorry about this Tim.

 

Just answering this for anyone else looking to load files from invoke. It turns out some string manipulation is required, but not much; just trimming the 'file:///' from the argument provided by the invoke framework is enough to work:

 

fName = fName.replace('file:///','');

 (this was referenced in the sample here: https://github.com/blackberry/BB10-WebWorks-Community-Samples/blob/master/Invoke-FileSystem-moimgur/...

BlackBerry Development Advisor
twindsor
Posts: 832
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: ReadFile and data manipulation

Actually I think this is an answer I needed myself for another issue I was working on. I'll have to give it a try. Thanks.

 

FYI That moimgur sample was done by a UCOSP student, so put another point down in the program's favour.

Tim Windsor
Open Source Technical Lead