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.
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');
-
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 });
-
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.
-
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.