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
Highlighted
New Contributor
Posts: 4
Registered: ‎07-14-2009
My Device: BB10
My Carrier: ATT
Accepted Solution

Is it possible to download images to shared folder and consume them in html?

Hello,

My requirement is to be able to download new images for a phonegap webworks application.

I am currently setting sandbox to false

I am requesting the filesystem and downloading a test jpg to blackberry.io.sharedFolder + /misc

I am seeing the file in my shared folder

 

Is it possible to use this in html or coverflow in the img src?

 

I have tried taking the fullPath return value from blackberry.io.sharedFolder +"/misc/test.jpg" and hardcoding it into src but no image appears. How would you access this?

 

Here is the entry.fullPath

filesystem:local:///persistent/accounts/1000/appdata/Example.xxx/shared/misc/test.jgp.

If it is possible to do what needs to go into img src?

Thanks, I appreciate any help I can get.

 

 

New Contributor
Posts: 4
Registered: ‎07-14-2009
My Device: BB10
My Carrier: ATT

Re: Is it possible to download images to shared folder and consume them in html?

I found this out on another thread. It works with:

src="file:///accounts/1000/shared/misc/aquarium_home.jpg"

 

I did hear somewhere that accounts/1000 could change though. If there is a better way let me know.

Thanks,
Todd

Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Is it possible to download images to shared folder and consume them in html?

I'm accepting your own response as the solution but just wanted to add two more things:

 

1) In your config.xml, you will need to whitelist the file:///accounts/ uri via the <access> element.

 

2) You can use the IO APIs to use the variable representing the shared folder instead of hardcoding a path:

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

 

If the path were to ever change, that variable should be updated to reflect that.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
New Contributor
Posts: 4
Registered: ‎07-14-2009
My Device: BB10
My Carrier: ATT

Re: Is it possible to download images to shared folder and consume them in html?

I have this working for shared folders but my requirement is that the user can't delete any of the files without deleting the application. Is there a way to use persistent storage instead of shared folders to store the image and use it in html?

 

I am able to download to the persistent storage but I am unable to access it from src=. 

 

For example, I downloaded a file to persistent/Concept folder

I then have tried many ways to access it. One way was the following:

src="file:///accounts/1000/appdata/Example.gYABgKyhjC35S88SWPhFYE6jjww/data/Concept/aquarium_home.jpg

 

The file seemed to have downloaded but I am unable to view it. 

Thanks,

Todd

Retired
Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10
My Carrier: Bell

Re: Is it possible to download images to shared folder and consume them in html?

Since you're downloading these images and saving them, you have access to the file blob (you need a Blob/ArrayBuffer object to pass into the fileWriter in order to save something).  You can obtain a useable URL to pass to any src attribute from this blob like so:

 

var src=window.URL.createObjectURL(imageBlobVariableThing);

someImgEl.src=src;

 

And voila!  It works Smiley Happy  This gets you away from using the messy '/account/whatever' nonsense as you won't always have permission to access directories.  ALSO, it abstracts the URL to point to data and not a file, so it doesn't matter where you've saved it (being shared folder, app sandbox, or html5 filesystem sandbox).

 

Hope that helps!

------------------------------
@grahamzibar
-_- zZZ