Files downloaded using FileTransfer.download disappear after removing app from memory (iOS)

5 posts, 0 answers
  1. Artem
    Artem avatar
    5 posts
    Member since:
    Dec 2014

    Posted 16 Dec 2014 Link to this post

    Here is the sequence of actions which will lead to the issue:
    1. Call FileTransfer.download while internet is available
    2. Using given file entry call $.ajax to load contents, no errors, data is available
    3. Remove app from memory
    4. Disable internet access
    5. Open app again
    6. FileTransfer.download calls error handler where $.ajax called with the same path calls it's error handler with "Not found" status

    Removing #4 from this sequence will lead to #2 instead of #6

    Who can explain what's going on behind the scenes, please?

  2. Artem
    Artem avatar
    5 posts
    Member since:
    Dec 2014

    Posted 16 Dec 2014 in reply to Artem Link to this post

    Forgot to mention that i'm using App Builder on iPad
  3. Artem
    Artem avatar
    5 posts
    Member since:
    Dec 2014

    Posted 18 Dec 2014 Link to this post

    Found the reason. It looks like FileTransfer.download deletes the file first, then tries to download new one.
    When there is no internet connection available local file will disappear to the blue wonder.

    My opinion - such behavior is not normal. You should remove local file only if remote one is available.
  4. Zdravko
    Admin
    Zdravko avatar
    657 posts

    Posted 19 Dec 2014 Link to this post

    Hello Artem,

    Indeed, this is an unexpected behavior that I was able to reproduce. I found an item logged in Cordova's bug tracker about the the same case and would recommend voting for it. FileTransfer plugin is mostly developed by Cordova's team and its community contribution so I can only provide you workarounds.

    As soon as they implement a fix in any plugin's version you should be able to take advantage of it by importing this particular version in your app and disable the integrated one.

    Here are a few workarounds that you can try until a fix arrives:
    • Call the download method only when the app has internet access. You can check that using the Cordova events.
    • Change file name or destination every time.
    • Once downloaded move the file. 
    • I was able to lock the file (in my case image) by using it as a source for a HTML img tag. This prevents its deletion.
    • Store the image in the localStorage

    Please let me know if I can be of further assistance.


    Regards,
    Zdravko
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Artem
    Artem avatar
    5 posts
    Member since:
    Dec 2014

    Posted 19 Dec 2014 in reply to Zdravko Link to this post

    Zdravko, thanks alot for your reply!
    I ended up with almost the same solution: i'm checking the connection availability before downloading.
Back to Top