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
Contributor
Posts: 12
Registered: ‎07-07-2012
My Device: 9860
My Carrier: Rogers
Accepted Solution

Cannot read file from shared folders on playbook

Hi,

 

I'm creating a very simple applications which reads an XML file in the Documents directory and attempts to parse it for some content. I can only seem to parse the file if it's in the root directory of my application so as a workaround, I was hoping to copy the file from the source into a "temp.xml" in my root directory and parse the "temp.xml" in my "processXml()" function. I am having issues with reading the file and i'm not sure what the problem is. my config.xml has "access_shared" permissions set.

 

my alert statements fail after the line 

"blackberry.io.file.readFile(filePath,handleOpenedFile);"

 

The failing code is attached below.

 

I ask the user to select the file using 

 

<input type="file" id="files" name="files[]" />

<script>
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>

 

I handle the file selection as shown below.

 

function handleFileSelect(evt) {
files = evt.target.files; // FileList object
readFile(files[0].name);

processXML();
}

 

function readFile(fileName){
var filePath = blackberry.io.dir.appDirs.shared.documents.path + '/' + fileName
blackberry.io.file.readFile(filePath,handleOpenedFile);
}

 

function handleOpenedFile(fullPath, blobData) {
blackberry.io.file.saveFile("temp.xml", blobData);
}

 

any help would be appreciated.

Developer
Posts: 314
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN

Re: Cannot read file from shared folders on playbook

Hi there!

You didn't show the relevant parts of config.xml.

Check if you have access permissions to the folders you are trying to access.

Example

 

(for the device memory)

<access subdomains="true" uri="file:///store/"/>

(for sdcard)
<access subdomains="true" uri="file:///SDCard/"/>

 

Also, use a try catch to see what the error really is, maybe the path is not correct.

 

Happy coding!

Nuno
Contributor
Posts: 12
Registered: ‎07-07-2012
My Device: 9860
My Carrier: Rogers

Re: Cannot read file from shared folders on playbook

Thanks Nuno,

 

I verified the config.xml for the permissions and they seem correct as shown below.

 

<access subdomains="true" uri="file:///store/">
<feature id="blackberry.app.event" required="true"/>
<feature id="blackberry.invoke"/>
<feature id="blackberry.io.file"/>
<feature id="blackberry.io.dir"/>
<feature id="blackberry.ui.dialog"/>
</access>

 

I also tried putting try catch statements as you mentioned in the two functions and neither of those caught any error either.

 

function readFile(fileName)
{
try{
var filePath = blackberry.io.dir.appDirs.shared.documents.path + '/' + fileName
blackberry.io.file.readFile(filePath,handleOpenedFile);
}
catch(e)
{
alert("error in readFile: " + e.message);
}
//return filepath;
}

function handleOpenedFile(fullPath, blobData) {

try{
//alert("file opened was: " + fullPath + " which contained " + blobData.length + " bytes");
blackberry.io.file.saveFile("temp.xml", blobData);
}
catch(e)
{
alert("error in handleOpenedFile: " + e.message);
}
}

Developer
Posts: 314
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN

Re: Cannot read file from shared folders on playbook

Hi
Forgot to ask, what device are you targetting? The paths I have you were for smartphones. PlayBook is different.
Nuno
Contributor
Posts: 12
Registered: ‎07-07-2012
My Device: 9860
My Carrier: Rogers

Re: Cannot read file from shared folders on playbook

Hi Nuno,

 

I am developing for the playbook. What should the URI path be in that case?

 

Thanks,

 

Raj

Contributor
Posts: 12
Registered: ‎07-07-2012
My Device: 9860
My Carrier: Rogers

Re: Cannot read file from shared folders on playbook

[ Edited ]

Thanks for the help nuno.. I managed to fix it by changing it to "file:///accounts/" in config.xml. However, i'm still unable to read anything from the file. I get the following error when attempting to read the file.

 

 "ReferenceError: Can't find variable: blackberry".

 

I tried looking at the forums and found one previous post.

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/can-t-access-blackberry-io-api-i...

 

But this seems to indicate that the problem is with the page_load event. I am not using any events other than the input file change event. The application itself loads fine but when the "blackberry.io.file.read" API call is invoked, that is when the error above appears.

 

Any ideas?

 

Raj

Developer
Posts: 314
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN

Re: Cannot read file from shared folders on playbook

Hey, did you manage to solve this?

Nuno
Contributor
Posts: 12
Registered: ‎07-07-2012
My Device: 9860
My Carrier: Rogers

Re: Cannot read file from shared folders on playbook

Thanks for checking in Nuno.

 

I managed to find the problem. It was in my config.xml and it was solved based on Adam's recommendation in the link below.

 

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/blackberry-io-dir-appDirs-not-wo...