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 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

— asked April 6th 2010 by Juan Bermudez
  • data
  • filesystem
  • save
  • webview
0 Comments

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

    — answered April 6th 2010 by Bruce McTigue
    permalink
    1 Comment
    • Bruce this post has helped me a lot could you tell me how to make this for multiple images rather than one

      Thanks

      — commented February 3rd 2013 by Muhammad Wahhab Mirza
  • 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 ?

    — answered April 2nd 2013 by Kristaps Horns
    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.