Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

How do I use a saved image path?

K, here's the run down…

  1. Get image from the photogallery or camera
  2. When image is selected, I write a temporary file to the filesystem and record the nativePath in an app.property
  3. On a different view, I'd like to use that image. How do I use a saved image path?

Everytime I do what's below, the app can't find the path. Should I be using 'url', 'path', 'backgroundImage', 'motherfuton', what?

var thumb = Titanium.App.Properties.getString('theImage');
Titanium.API.info('READING IT IN: '+thumb); // this outputs correctly 
var thumbView = Titanium.UI.createImageView({
    url:thumb
});
view.add(thumbView);

Error info generated by the console:

[ERROR] Failed to load image: (null), Error: Error Domain=ASIHTTPRequestErrorDomain Code=5 UserInfo=0x503f2a0 "Unable to create request (bad url?)"
— asked March 30th 2010 by Christopher Webb
  • 0_o
  • image
  • iphone
  • mobile
  • path
  • property
  • url
  • voodoo
0 Comments

5 Answers

  • Accepted Answer

    Try this:

    var thumb = Ti.App.Properties.getString('theImage');
    var file = Ti.Filesystem.getFile(thumb);
    var thumbView = Ti.UI.createImageView({
        image:file
    });
    view.add(thumbView);
    

    See, eg, image_view_file.js.

    — answered March 30th 2010 by James K
    permalink
    0 Comments
  • First off, let me just say that I appreciate your time. I appreciate the code snippet and the link. Unfortunately this didn't work for me:

    var thumb = Ti.App.Properties.getString('theImage');
    var file = Ti.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,thumb);
    var thumbnailView = Titanium.UI.createImageView({
        url:file
    });
    view.add(thumbnailView);
    

    Gives me this:

    [ERROR] Failed to load image: (null), Error: Error Domain=ASIHTTPRequestErrorDomain Code=5 UserInfo=0x503b2b0 "Unable to create request (bad url?)"
    
    — answered March 30th 2010 by Christopher Webb
    permalink
    0 Comments
  • I used the image property in my code, not the url property - did you try that too?

    You also don't need to pass Titanium.Filesystem.resourcesDirectory as a parameter to getFile if you're storing the full path. The getFile function just concatenates its parameters.

    — answered March 30th 2010 by James K
    permalink
    0 Comments
  • Thanks again for checking back. Yes, sir. Sorry about that - I tried the url version last then copied and pasted. I used the image version to no avail.

    I saw another version of this example floating around and it used a different Filesystem location, and I tried each, but that didn't work either.
    Titanium.Filesystem.resourcesDirectory vs. Titanium.Filesystem.applicationDataDirectory

    Not entirely sure what the differences are, but I tried them anyway. Any ideas?

    — answered March 30th 2010 by Christopher Webb
    permalink
    0 Comments
  • I also tried fireEvent to pass the value of the event.media to the imageView, but that didn't work either. I'm kind of at my wits end here. Anybody?

    — answered March 31st 2010 by Christopher Webb
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.