Part of some code i'm working on downloads a series of *.png files from a web server. There should be a total of 65 files, but often the web server has missing files. So for argument's sake say only 35 of the 65 files are available.
Before I download, I create a list with 65 entries, with each entry being the web address for each of the files.
To deal with this i've decided to substitue the missing files with a proforma *.png file that is built-into the app. I do this by checking if I get a 404 error code when I .Get the files from the server:
This system works fine. I can check my AppSpecificDirectory, and the correct files are present - a mix of the downloaded files and the substitute *.png files.
However, when I come to display the images - basically a forward and backwards button that calls this routine:
... only the downloaded images display. when the list index gets to a filename that was missing and I substituted, the substitute image does not display - it just leaves the last known good file on the screen until I click through to the next "good" downloaded file.
Anyone have any thoughts on what may be happening?
I've checked the substitute *.png files and the load fine in my phone's gallery.
I'm creating the list in earlier code. There are 65 line items in the list that are generated through separate calculation before any .Get process commences.
I then set the "filename" for each individual .Get as the the respective index line item from the list. I have a debug text field I can watch the .Get code step through each one sequentially.
You can see the above code where I copy an internal AUS_Blank.png to the file name if I get a 404 error code as part of the .Get process.
After a download sweep is complete, I check the actual files present in the ASD and they are all named correctly and they all align with the items in the list. Some of the *.png files are the downloaded ones and others are the substituted ones I've copied over from the internal asset AUS_Blank.png. There are 65 files as expected and I can open every file using the phone gallery app with no issues.
The back and forward buttons I use to step through each of the 65 png files utilises the exact list as the the download sweep does. No changes.
I've copied the text file name of one of the substituted png files to ensure there's no stray space or odd character in the filename, but it appears to be correct when I compare it in a text editor.
I've also tried copying one of the "good" downloaded png files over the top of one of the png files generated from the internal assets. This file is not being displayed either.
I wonder if there's some kind of cache action going on?
Perhaps the .Got returning the 404 error is somehow still being linked to the filename and the system is somehow telling the colintree async loader that the file doesn't exist even though it is clearly in the ASD?
That would be good practice anyway - have 65 'blank' substitutes in the directory and overwrite them with the downloads - no 404 error checking required (there could be other errors!) .
You would need to compare in hex since the characters could look the same but the bytes could be different. You can also get in trouble with characters that have multiple versions in Unicode (App Inventor defaults to UTF8) versus ASCII.
Do you absolutely have to use the Colin Tree extension? When was it last updated? I suspect it might be out of date.
I'll review my code when back in front of the computer.
One thing I will mention. The list items and therefore the address for the files I'm downloading and the final filename is in the format of a Web address, I.e.:
I wonder if the app is using a cached copy of the good files, but seeking the bad (substituted) files from the ASD? Perhaps the // in the path and filename is perhaps resetting the read path to the incorrect (asset) location?
Will look into it changing it, however, it's a great way of avoiding extra coding because, overall, there are three web servers in total and the files automatically file themselves by webserver.
I've checked the filename text using Notepad++ and the filename is exactly the same as the web address, which is the same as the list item.
I also hex-compared the original AUS_Blank.png file that I created myself with the version that the app substitutes and they also both exactly the same.
What makes you suggest that idea? They might be temporarily held in memory cache (to be assembled) but if they were stored you should be able to see that by recording before and after device storage size.
My reasoning is the broken code I was using to retrieve images for display. Despite my code pointing to the incorrect local file location, the "good" downloaded files were still being displayed. These "good" files were the ones successfully downloaded from web. I was specifically naming each of these files by setting the .Response Filename before each file was attempted to be retrieved from web.
Each file has a filename associated with it. When I tried to retrieve each file to display, the system couldn't find the file, so it used the next best thing - an asset file that I had downloaded during the session.
That's my theory anyway. Can you think of another reason why only the "downloaded" files were being displayed and not the ones I was simply copying from assets to ASD?
For clarity, after each download sweep, all 65 files are in the ASD and are viewable.