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
Posts: 48
Registered: ‎10-11-2012
My Device: Z10
My Carrier: none

How to load image from "data" folder into WebView ?

Hello !

I am trying to load local html page that contains img loaded by the app in "data" folder, so in the html doc image must be inserted like as

<img src="local:///data/this_is_img.png" alt="My Image" />

 and this is not working, also if img has full path starting from "file://"

 

But if image is located in assets this is working :

<img src="local:///assets/this_is_img.png" alt="My Image" />

 So, question is how to insert image from data folder ?

 

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How to load image from "data" folder into WebView ?

[ Edited ]

Because it's not local, it can be accessed using QDir::homePath()...

 

http://developer.blackberry.com/native/documentation/cascades/device_platform/data_access/file_syste...


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 48
Registered: ‎10-11-2012
My Device: Z10
My Carrier: none

Re: How to load image from "data" folder into WebView ?

I found that this is maybe a problem because similar question was not solved

http://supportforums.blackberry.com/t5/Native-Development/Access-to-app-s-working-directory/td-p/262...

 

I tried this but only the first image is displayed, so how to open image from data folder ?

<img src="local:///assets/main_menu_menu_btn_selected.png" alt="My Image" />
<img src="file:///main_menu_menu_btn_selected.png" alt="My Image" />
<img src="file:///../../../../../../data/icons/resize/72x72/182.png" alt="My Image" />
<img src="file:///../../../../../data/icons/resize/72x72/182.png" alt="My Image" />
<img src="file:///../../../../data/icons/resize/72x72/182.png" alt="My Image" />
<img src="file:///../../../data/icons/resize/72x72/182.png" alt="My Image" />
<img src="file:///../../data/icons/resize/72x72/182.png" alt="My Image" />
<img src="file:///accounts/1000/appdata/com.example.testapp.testDev_mple_testapp5dbaf0_/data/icons/resize/72x72/184.png" alt="My Image" />
<img src="file://accounts/1000/appdata/com.example.testapp.testDev_mple_testapp5dbaf0_/data/icons/resize/72x72/184.png" alt="My Image" />
<img src="file:///accounts/1000/appdata/com.example.testapp/data/icons/resize/72x72/184.png" alt="My Image" />

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How to load image from "data" folder into WebView ?

You'll see from that post that I indictated a difference between how file: and local: are handled within WebView.

 

Your only option currently is to place you files in a shared directory and access from there.

Remembering to remove the files after use so not to fill the users folders, I would recommend a tmp folder.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How to load image from "data" folder into WebView ?

To allow access via the file mechanism for the browser or webview would violate security of an apps directory.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 48
Registered: ‎10-11-2012
My Device: Z10
My Carrier: none

Re: How to load image from "data" folder into WebView ?

So WebView have not the same right as app ? And I have to interact with WebView as with third party application using shared folder  ?

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How to load image from "data" folder into WebView ?

Effectively yes.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 48
Registered: ‎10-11-2012
My Device: Z10
My Carrier: none

Re: How to load image from "data" folder into WebView ?

Thank you I'll try, but this behavior is very strange and not clear.

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How to load image from "data" folder into WebView ?

If you think of it from a security point of view it makes perfect sense for file and local to be handled differently, what's not clear however is why local is not able to access the data directory I see no reason why a relative path should not work.  However I have tried many variations and cannot get it to work so there is some underlying mechanism there for some reason currently only clear to the OS designers. 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Highlighted
Developer
Posts: 48
Registered: ‎10-11-2012
My Device: Z10
My Carrier: none

Re: How to load image from "data" folder into WebView ?

tried with no luck, no images are displayed

(permissions added, image is copied to shared folder)

<img src="file:///shared/misc/testapp/icons/resize/72x72/182.png" alt="My Image" />
<img src="file:///accounts/1000/appdata/com.example.testapp.testDev_mple_testapp5dbaf0_/shared/misc/testapp/icons/resize/72x72/182.png" alt="My Image" />