Substituted PNG Files Not Displaying


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.

How/When are you generating your list of files to display ?

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?

Can you display one of the "asset" png files just using normal blocks to the image component ?

Can you display the image in the assets the same way?

Do the "asset" png files have the correct file size ?

Remind me which android version you are using, also testing as apk or in companion mode

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.

No. Using the inbuilt set image1.Picture fails to load any of the substituted png files.

Yes. I can load this into the image holder no problems.

Yes, they all have the correct kilobytes.

I'm using andoid 11 and i'm testing apk's on the phone.

At this stage, yes. The standard set image1.picture function slows the app down way too much.

How would I best do this?

I've tried telling the system that the download was all good by adding set.responseCode to 200, but this also makes no difference:

I put together a simple test app. I had to use these blocks in order to display the image testSheets.png. Compiled and tested on Android 11.


Thanks @TIMAI2

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

(Note the // in there)

Therefore when I save the files to the ASD, they are written into the folder structure:


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?

Use a code editing IDE such as Ultra Edit or Notepad++

I think that will lead to problems, even if it is not the current problem. Just save the file to the ASD folder without any extended path.

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.

But like you say, it might create other problems.

Just make a mini Project to test.

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.

1 Like

@TIMAI2, Thank you. It came down to being very specific about where to tell the procedures to find the file. My previous code was this:

But as you've pointed out in your test code, you need to be very specific about where to look, therefore I've changed the code to this:

The code now works as I was hoping.

1 Like

Begs the question...

The files I am downloading successfully from the Web- these are being saved AND being stored in some kind of cache?

Is there some kind of documentation on how the Web.get system works and stores files?

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.