0

I'm building an app in flash builder 4.6, I have the files (jpgs flvs etc) online, but in order to save bandwidth I download the files to the userfolder so they are downloaded only once, up to this point all nice and dandy but, I need to check if a file that is already in my userfolder on the mobile has been updated online and re-download it. I tried looking for an example of this everywhere with no luck.

Thanks for the help in advance.

2 Answers2

0

Well, to check the files inside your folder, the simple var files:Array = assets.getDirectoryListing(); give you what you need,

Now the problem is how to know if your files are updated or not ... basically if they always have the same name you just can't ... what I did, is generating a random number, each time to add new files, and add it to the file name, and when you'll check, if you have the same number so no need to update, and in the other case you update,

This is just an idea of what you can do, if you're interested, I can help you along,

Cheers !!


Here is an example that might make it a little clearer : what I did is :

The file name on the xml look like this : file_name?123123 and when I read the xml once again I do this to check :

var arr1:Array = filename.split("?"); // file name from the localStorage
var arr2:Array = xml.file.name.toString().split("?"); // file name from the XML file
if(arr1[arr1.length -1] != (arr2[arr2.length -1]){
   //download the new file and replace the old file
}

ps : I have done this with ? because @ made some problems when reading the xml, and since I'm working on Windows, and it doesn't accept that in the file name so before storing it I change the file name by just fileName.split("?").join("@");

Khalil Bhm
  • 394
  • 3
  • 13
  • Thanks, I got as far as that, the thing is I didn't want to change the file names. I'm already checking if the files are on the device and if not downloading them as needed. I was hopping at least for a size verification to see if the two versions where the same, I know that's not fail proof but it could be a start :) If that's not possible I can allways change the file name and the entry in the xml delete the old one and download the new, it just adds 1 step in the process and a few lines of code. – Paulo Pocas Oct 22 '13 at 14:28
  • You could use an HTTP HEAD request on the image files to get the size and last modified date on the server. You'll just need to use HTTPService to be able to make it a HEAD instead of a GET request. – Brian Oct 22 '13 at 15:33
  • Sry, I was working, I edited my answer, hope this example explains what I mean – Khalil Bhm Oct 22 '13 at 22:16
0

I personally do similar with app config files. The majority of my app's content is driven entirely by APIs I write and the APIs can, at times, generate massive amounts of JSON data for the app to consume. To avoid downloading this data (usually about 200-300kb) on startup every single time, I follow this pattern:

  1. Check if file exists (File.exists)
  2. If file does not exist, send request to server for config file with a parameter of update and a value of 0. This ensures no Unix timestamp will ever be less than this
  3. If file does exist, send the File.modificationDate.time as the update value
  4. On the server, check if the update is older than the modification time of the data (I save a timestamp to an SQL database whenever the database is updated, though you could just check the modification time on the file itself)
  5. If the update is older, send the data. If it is newer, send a simple json message. I usually send something like {'valid':'no new data'}

This will obviously require a bit of work handling the JSON return on the AS3 end as well as some PHP, but it definitely works and should be applicable to any similar situation

Josh
  • 8,079
  • 3
  • 24
  • 49