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

Native 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
Highlighted
Contributor
Posts: 29
Registered: ‎05-28-2013
My Device: z10
My Carrier: rogers

Access to the data folder in javascript

I implemented Web View in QML that points to an html file. The Web VIew is loading an html file located under the assets folder. I also have a text file created in the application's /data directory. Is there a away to open the text file in the javascript? It seems it can't find the file no matter if I put the relative or absolute path. It looks like the javascript is always  looking the file under the /assets directory.

 

Is it even possible?

 

Thanks.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Access to the data folder in javascript

It should be possible to reach it, if nothing else, by using an absolute path that looks like /accounts/1000/appdata/yourappsandboxhere/data/yourfile.html

If you aren't purely in QML, you should be able to get most of that path from the system rather than hardcoding it. There are a variety of tools including the HOME environment variable, or (I believe) QDir::homePath() and maybe others.

I'd start with a simple hardcoded absolute path so you can (should) be sure of getting it working, then replace with one of the better options.

If you've already tried hardcoding an absolute path, you should probably show some sample code and/or output from your log or whatever, showing us more detail.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 105
Registered: ‎09-06-2013
My Device: Z10

Re: Access to the data folder in javascript

In javascript do u mean in qml? If yes , create a class that extends QObject, add the relevant macros, add your method, you should be able to use it in your QML just fine.

Contributor
Posts: 29
Registered: ‎05-28-2013
My Device: z10
My Carrier: rogers

Re: Access to the data folder in javascript

I mean in javavacript. I have no problem loading the html page in QML. For example, here is the snippet of javascript code:

 

<html>

  <head>

   <script src="https://www.google.com/jsapi"></script>

   <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

<script src="http://code.jquery.com/jquery-migrate-1.1.1.min.js"></script>

    <script src="js/jquery-csv-0.71.min.js"></script>

 

    <script type="text/javascript">

      google.load("visualization", "1", {packages:["corechart"]});

      google.setOnLoadCallback(drawChart);

      function drawChart() {

      

  // grab the CSV

  $.get("data.csv", function(csvString) {

 

....process file........

 

 

Interestingly the code above works because the csv file is located in the asset folder. But when I create it dynamically and store it in the data folder it can't read it. I have shared permission enable for the app.

 

I tried changing the path to "../../../data/data.csv" as well as the absolute path. None worked.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Access to the data folder in javascript

What about providing a schema of "file:" in front, as in "file:///the-absolute-path-goes-here" ?

I haven't tried this lately but I think I had some variant of that working last summer during early experimentation.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Contributor
Posts: 29
Registered: ‎05-28-2013
My Device: z10
My Carrier: rogers

Re: Access to the data folder in javascript

No. That didn't work.

Contributor
Posts: 29
Registered: ‎05-28-2013
My Device: z10
My Carrier: rogers

Re: Access to the data folder in javascript

To be more specific. When I tried to get the full of the working directory in the javascript, i get "/assets/". I don't think it knows or have permissions to the shared folders.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Access to the data folder in javascript

If you're trying to get this file from your app's own data/ folder then the access_files permission (which is for the shared/ folder) is not required.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!