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 to display the jpg image from applicationData Directory

Here is my code, which does not display:

var f=Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "a.jpg");

var contents = f.read();

var magCover1 = Titanium.UI.createImageView({
url: content,
height:145,
width:114,
bottom:10
});

can anyone help this?
thanks

— asked August 12th 2010 by Kyle chang
  • applicationdata
  • directory
  • display
  • from
  • image
  • jpg
  • the
0 Comments

5 Answers

  • im totally new to titanium but shouldn´t it be
    url: contents
    ?

    maxi

    — answered August 12th 2010 by maxi buschmann
    permalink
    1 Comment
    • you are correct. Kyle has a spelling error too.

      — commented August 13th 2010 by Sindre Sorhus
  • You have to add it to a view.

    var win = Ti.UI.currentWindow;

    win.add(magCover1);

    — answered August 12th 2010 by Sindre Sorhus
    permalink
    0 Comments
  • In case anyone is searching for a solution to displaying an image from the Application Data directory from within a webview, or in a Desktop application. Any references to the file need to be prefixed with file:///

    http://blog.rapiddg.com/2011/04/reference-application-data-files-when-creating-a-titanium-desktop-application/

    — answered April 6th 2011 by Mike Bopp
    permalink
    1 Comment
    • Hi Bopp, I am searching for the same issue .When i open this URL it needs some authentication.Please guild me how to get the solution on this link.Thanks for sharing.

      — commented June 25th 2013 by Ali Akram
  • var f=Ti.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "a.jpg");
    var magCover1 = Ti.UI.createImageView({
      url: f.nativePath, 
      height:145, 
      width:114, 
      bottom:10
    });
    

    The nativePath property works also

    — answered April 6th 2011 by Aaron Saunders
    permalink
    1 Comment
    • 'url' is deprecated. use 'image' (but I'm sure you knew that ;) )

      — commented April 6th 2011 by Kosso
  • Try :

    
    var data_dir = Ti.Filesystem.applicationDataDirectory;
    var image_name = 'a.jpg';
    
    var magCover1 = Ti.UI.createImageView({
      image: data_dir+'/'+image_name, 
      height:145, 
      width:114, 
      bottom:10
    });
    
    — answered April 6th 2011 by Kosso
    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.