This is a migrated thread and some comments may be shown as answers.

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

4 Answers 31 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Artem
Top achievements
Rank 1
Artem asked on 16 Dec 2014, 03:51 PM
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?

4 Answers, 1 is accepted

Sort by
0
Artem
Top achievements
Rank 1
answered on 16 Dec 2014, 04:17 PM
Forgot to mention that i'm using App Builder on iPad
0
Artem
Top achievements
Rank 1
answered on 18 Dec 2014, 11:46 AM
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.
0
Zdravko
Telerik team
answered on 19 Dec 2014, 02:49 PM
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.

 
0
Artem
Top achievements
Rank 1
answered on 19 Dec 2014, 05:45 PM
Zdravko, thanks alot for your reply!
I ended up with almost the same solution: i'm checking the connection availability before downloading.
Tags
General Discussions
Asked by
Artem
Top achievements
Rank 1
Answers by
Artem
Top achievements
Rank 1
Zdravko
Telerik team
Share this question
or