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
jacquie-callahan
Posts: 12
Registered: ‎10-13-2012
My Device: Playbook
Accepted Solution

How do I get the pathname to Pictures directory on the playbook?

I am developing a drawing app that includes a save file function.  I want to save the image to an album in the general pictures directory on the playbook. Then the user should be able to view their saved drawing from a photo album in the picture directory.  I have found all sorts of examples on how to do this for app shared directory (using blackberry.io.dir.appDirs.shared.camera.path)  But, I haven't found out how to get to the general (non-app specific) pictures directory.  How do I get to that directory using javascript?  

Please use plain text.
Developer
jamesgibbons
Posts: 26
Registered: ‎06-01-2010
My Device: Dev Alpha, PlayBook

Re: How do I get the pathname to Pictures directory on the playbook?

My guess is that you want to use the following path for saving the pictures:

 

blackberry.io.dir.appDirs.shared.photos.path

 

If you ever want to find all shared directories you can do the following:

 

console.log(blackberry.io.dir.appDirs.shared);

 

On my PlayBook this gives:

  1. bookmarksObject
  2. booksObject
  3. cameraObject
  4. documentsObject
  5. downloadsObject
  6. miscObject
  7. musicObject
  8. photosObject
  9. printObject
  10. protected_mediaObject
  11. videosObject
  12. voiceObject

 

Let me know if this works.

 

Cheers,

 

James

 

 

___________________________________________________________
My latest Blackberry 10 app Audiobooks! :smileyhappy:

My latest PlayBook app Photojam!

Find me on Twitter: GoGibbons
Please use plain text.
Contributor
jacquie-callahan
Posts: 12
Registered: ‎10-13-2012
My Device: Playbook

Re: How do I get the pathname to Pictures directory on the playbook?

Thanks James.  I tried using shared.photos instead of shared.camera, but this still doesn't solve my problem.

 

My ultimate goal is to get something stored into Pictures on the playbook.  I want the user to be able to click on the Pictures icon, then be able to find his/her newly saved drawing in an album.

 

Here is a code snippet (using shared photos):

---------------------------------------------------------------------------------------------

 var currentImgData = currentCanvas.toDataURL("file/jpeg");
 
  //convert currentImg to blob data
  currentImgData = currentImgData.replace('data:image/jpeg;base64,', '');
  //Testing save
  //document.write('<img src="'+currentImgData+'"/>');
  var currentBlobData = blackberry.utils.stringToBlob(currentImgData, 'binary');
  alert("created blob data");
 
  //Generate unique file name
  var numRand = Math.floor(Math.random()*9999999);
  alert ("random number generated: " + numRand.toString());  
 
  try{
     var Dir = blackberry.io.dir;
        var path = Dir.appDirs.shared.photos.path;
      alert ("path = " + path);
  }
  catch(e)
  {
   alert("error in saveFile: " + e.name + " " + e.message)
   }

  var filename = path + "/JustDraw"+ numRand.toString() +".jpg";
  alert ("Checking to see if file exists: " + filename);
  while (blackberry.io.file.exists(filename)) {
        //then generate new filename
        numRand = Math.floor(Math.random()*9999999);
        var filename = path + "/JustDraw/"+ numRand.toString() +".jpg";
   }
   //Save blob daga image to file
   alert("Saving file to: " + filename);
   try {
   blackberry.io.file.saveFile(filename, currentBlobData);
   //blackberry.io.file.saveFile(fileDir + "/test.jpeg", final_image_blob);
   } catch (e) {
      alert('e.message = ' + e.message);
   }
   
   alert ("file saved to: " + filename);

----------------------------------------------------

 

My blob data save seems to work, as I can write the image to the screen successfully.  I get through all my alert messages with no errors. (I'm also having problems with web inspector hence all of the alerts.)  According to my alert messages, my file is ultimately saved to:

file:///accounts/1000/appdata/jDrawApp...riduculouslylongstringofcharacters.../shared/photos

 

This does not result in any new image being added to the playbook's pictures.

 

My problem is: how do I get the file saved to the Pictures directory,  so that the user can directly access it outside of my app?

 

I am running OS 2.1.0.1032 on my blackberry.  I have the following settings included in my config.xml file:

-----------------------------------

    <rim:smileytongue:ermissions>
        <rim:smileytongue:ermit>access_shared</rim:smileytongue:ermit>
    </rim:smileytongue:ermissions>

 

    <feature id="blackberry.io.file" required="true" />
    <feature id="blackberry.io.dir" required="true" />

------------------------------------
   

 

-Jacquie

Please use plain text.
Contributor
jacquie-callahan
Posts: 12
Registered: ‎10-13-2012
My Device: Playbook

Re: How do I get the pathname to Pictures directory on the playbook?

[ Edited ]

well without the smiley faces which are actually ':smileytongue:' in my config file - nevermind

Please use plain text.
Developer
jamesgibbons
Posts: 26
Registered: ‎06-01-2010
My Device: Dev Alpha, PlayBook

Re: How do I get the pathname to Pictures directory on the playbook?

Hi Jacquie,

 

Sorry, I think I made a mistake. Can you try replacing this line of code:

 

var path = Dir.appDirs.shared.photos.path;

 With the following:

 

var path = "file:///accounts/1000/shared/photos";

 I looked over the rest of your code and it seemed fine.

 

 

 

___________________________________________________________
My latest Blackberry 10 app Audiobooks! :smileyhappy:

My latest PlayBook app Photojam!

Find me on Twitter: GoGibbons
Please use plain text.
Contributor
jacquie-callahan
Posts: 12
Registered: ‎10-13-2012
My Device: Playbook

Re: How do I get the pathname to Pictures directory on the playbook?

Tried that -- doesn't work either.  I also tried creating a new subdirectory in the shared/photos directory:

 

 

var path = "file:///accounts/1000/shared/photos/JustDraw";

if (!blackberry.io.dir.exists(path)){
       blackberry.io.dir.createNewDir(path);
   }

 But that doesn't work either.

 

 

Please use plain text.
Contributor
jacquie-callahan
Posts: 12
Registered: ‎10-13-2012
My Device: Playbook

Re: How do I get the pathname to Pictures directory on the playbook?

Ok.  I think this does work:    var path = "file:///accounts/1000/shared/photos/JustDraw"

 

When I connect the playbook to my desktop and look at the playbook's file structure on my desktop, I see a folder named "JustDraw" in the Photos folder. However, the files that were saved to the JustDraw folder are damaged or corrupt.  So, now I think my problem is in the blob or save parts.

 

-Jacquie

Please use plain text.
Developer
jamesgibbons
Posts: 26
Registered: ‎06-01-2010
My Device: Dev Alpha, PlayBook

Re: How do I get the pathname to Pictures directory on the playbook?

Hi Jacquie,

 

Glad the file is being saved. If your image is corrupted, did you edit the stringToBlob function so that it supports the binary data type? If not, look at the second post on this page by twindsor:http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/stringToblog-save-image-problem/....

 

Cheers,

 

James

___________________________________________________________
My latest Blackberry 10 app Audiobooks! :smileyhappy:

My latest PlayBook app Photojam!

Find me on Twitter: GoGibbons
Please use plain text.
Contributor
jacquie-callahan
Posts: 12
Registered: ‎10-13-2012
My Device: Playbook

Re: How do I get the pathname to Pictures directory on the playbook?

Almost!  Using this method, I can save a .png file.  But it doesn't work for saving a .jpg file :smileysad:.  I get undefined object when calling:  blackberry.io.file.saveFile(filename, currentBlobData);  This is a problem since my default background on a canvas is light grey, while the default background on a playbook photo is black.  Guess I'll have to paint in the background before saving.

 

At any rate, my original question regarding the photos pathname has been answered.  Thank you James!

 

-Jacquie

Please use plain text.