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

Reply
Developer
bobdodd
Posts: 116
Registered: ‎10-31-2012
My Device: BB10 Dev Alpha B
Accepted Solution

"asset:///" format not recognized in JsonDataAccess

[ Edited ]

This may well be a real bug, as opposed to just me getting it wrong....

 

This works:

bb::data::JsonDataAccess capability;
QVariant capabilityModel = capability.load("app/native/assets/capability.json");

 This doesn't:

bb::data::JsonDataAccess capability;
QVariant capabilityModel = capability.load("asset:///capability.json")

 

Do I have a typo that I can't see, or is this a real bug?

 

 

 

 

 

 

 

 

Developer
ekke
Posts: 1,571
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: "asset:///" format not recognized in JsonDataAccess

did you read the upgrade guide ? there are some changes with URIs

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Developer
bobdodd
Posts: 116
Registered: ‎10-31-2012
My Device: BB10 Dev Alpha B

Re: "asset:///" format not recognized in JsonDataAccess

did you read the upgrade guide ? there are some changes with URIs

 


I did and mis-understood :Wacko:

If you use relative paths and want them to resolve with the file:// prefix, this is not supported if your QML file was referenced with asset://. The asset:///a.qml file path will remain as asset:///a.qml and will not be resolved to the file path. 

Relative paths are now relative to asset:///a.qml If you are accessing a file that isn't located in your assets directory, you must use file:// to specify the file path (for files outside of your application’s asset directory). Only files in your assets directory should use the asset:// path. When asset:// is used, the selector code will be used and the resource file must exist within your assets directory.

Since my file is at the root of "assets" (not outside of it) in Momentics, I assumed that I should use asset://

But it doesn't work (neither two or nor three slashes). On the other hand the relative path to my asset doesn't start from "assets", if you look at what did work for me, the relative path (I don't start with a slash) is:

 

"app/native/assets/capability.json"

 

So that's a relative path from the root of my application.

 

I assume we shouldn't be pathing like this, so what should it be now?

 

 

BlackBerry Development Advisor
sabdelsayed
Posts: 249
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10

Re: "asset:///" format not recognized in JsonDataAccess

[ Edited ]

Hi bobdodd,

 

Thank you for you question!

 

The answer to your question is actually on the Working with JSON data page: https://developer.blackberry.com/cascades/documentation/device_platform/data_access/working_with_jso...

 

You need to do something like this:

 

JsonDataAccess jda;

QVariant list = jda.load(QDir::currentPath() +

                "/app/native/assets/employees.json");

               

… the file path specified in load() is constructed using the QDir::currentPath() function. This function returns the current working directory for an app, which is the application's sandbox directory. By adding a relative file path, you can specify the location of the .json file that you want to load. The path "/app/native/assets/" specifies the location of the assets folder in your project, which is where the employees.json file is located.

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Developer
bobdodd
Posts: 116
Registered: ‎10-31-2012
My Device: BB10 Dev Alpha B

Re: "asset:///" format not recognized in JsonDataAccess

I've marked it as "solved" Samar,.

 

but can you please improve the English in future release notes.

 

"Only files in your assets directory should use the asset:// path."

 

reads as "use asset:://" if your file is in "asset://".

 

All the release note needed to say was:

The use of asset:/// has been discontinued for file paths, please use /app/native/assets/ instead.

 

Btw things seem a little inconsistent at the moment. ImageView seems to still want the "asset:///" form  for file paths. When I changed it to the full path, it failed. So for Json  files I'm  use the new absoulte path format, but for ImageView I still use "asset:///". 

 

Why has one changed but not the other? I assumed it would be paltform-wide.

 

 

Bob

 

BlackBerry Development Advisor
sabdelsayed
Posts: 249
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10

Re: "asset:///" format not recognized in JsonDataAccess

Hello bobdodd,

 

Thanks again for your follow-up.

 

A RIM technical expert did a little test and has confirmed that all these formats for referencing images seem to work. The only one that didn’t seem to work was the absolute path: “/app/native/assets/images/tina.png”, which the upgrade guide meant to reference in the confusing section. However, the confusing paragraph has been updated and will be pushed to production soon. They have also confirmed that the Images documentation and the File System documentation are correct.

 

Samar

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker