Titanium Community Questions & Answer Archive

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

What is the URL for applicationDataDirectory

What is the URL for applicationDataDirectory? I am trying to call a file from a webview with its location in the applicationDataDirectory. If it was in the resourceDirectory I would call it with app://Resources/<myfile>.

Any help is appreciated.

— asked November 20th 2010 by General Usage
  • applicationdatadirectory
  • filesystem
  • iphone
  • mobile
0 Comments

4 Answers

  • Hi "General"! ;)

    I think the only way you can access a file in the appdata dir is using the Ti.Filesystem.getFile() method. Thus, you'd have to find some way of calling:

    Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'example.txt');
    
    — answered November 20th 2010 by Paul Dowsett
    permalink
    0 Comments
  • To expand on my previous answer, you could "inject" the file into your webview like this:

    var exampleFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'example.txt'); 
    if (exampleFile.exists()) {
            var exampleContent = exampleFile.read();
    }
    var htmlWrapperExampleContent = "<html><body><pre>" + exampleContent.text + "</pre></body></html>";
    
    var webView = Ti.UI.createWebView({
            html:htmlWrapperExampleContent,
            title:'Your Title',
            loading: true   
    });
    
    — answered November 20th 2010 by Paul Dowsett
    permalink
    0 Comments
  • Thanks for the quick responses.

    The problem that I have is that I have to call the file directly from an html page. If the file was in the resourcesDirectory I could reference it with app://Resources/<myfile> but it seems on the iPhone I can not write a file to the resourcesDirectory. So I am putting files in the applicationDataDirectory.

    — answered November 20th 2010 by General Usage
    permalink
    2 Comments
    • General, does my "inject" the file contents answer not help with this?

      — commented November 20th 2010 by Paul Dowsett
    • I could well be missing the significance of what you are saying. If you could explain why my last answer does not help, then I may be able to suggest something more suitable.

      — commented November 20th 2010 by Paul Dowsett
  • So I ended up getting the path and then setting the url as follows:

    app://Resources/../../../../../../../../..<path from Ti.Filesystem.applicationDataDirectory>/<myfile>;

    This seems to work. Hope this can help someone else.

    Once again thanks for all the responses. It helped me to investigate other ways of thinking about the problem that I had not considered.

    — answered November 20th 2010 by General Usage
    permalink
    1 Comment
    • Are you certain that will work on both iOS and android?

      — commented November 21st 2010 by Paul Dowsett
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.