How to use FileSystem
I am looking for a solution so i can save certain PDFs, to later show them in Webviews.
I looked at the Docs and couldnt really see how it works.
Do you have any examples on how i would save pdfs to the filesystem and then get them to show in a webview?
Thanks
2 Answers
-
Accepted Answer
Hi Juan,
I have some example code that downloads chart images from the net. The images are saved locally. I have image views inside regular views that have to be updated with the chart images. Here's the code:var xhr = Ti.Network.createHTTPClient(); xhr.onload = function() { oldf = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'chart.png'); if (oldf != null) { oldf.deleteFile(); } f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'chart.png'); f.write(this.responseData); myView.remove(myImageView); myImageView = Ti.UI.createImageView(); myImageView.url = f.nativePath; myView.add(myImageView); }; xhr.open('GET',imageUrl); xhr.send();
Hope this helps.
Bruce
-
You currently use
Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'chart.png');
, which means that you know the name and extension of the file. What happens in a situation, where you select a file from the list, so you want to get a file that you do not know the name and extension for ?
I was trying something like this :
var mediafile = Ti.Filesystem.getFile(tempDir.nativePath, Ti.Filesystem.getFile(tempDir.nativePath).name);
but how do I get file extension for it ?