Images take too long...I think?

What I’m trying to do:

I have several “buttons” on a form in the form of links to make a semi-calculator. Each link has an image on it, and each image is a nicely made png. Looks great!

However, on a few of the “buttons” I’d like the png image to change depending on circumstances that the user enters. So I’ve stored a few png’s in a data table, and load them when the form initialises:

self.a = app_tables.temp_counts.get(uid='1')['picture']
self.b = app_tables.temp_counts.get(uid='2')['picture']

What I’ve tried and what’s not working:
Well, everything is working but there’s a second delay after the link is tapped, the image goes blank, then the new image appears as it should:

def change_button(self,**event_args):
if self.test:
  self.image_4.source = self.a
else:
  self.image_4.source = self.b
self.test = not self.test

I’m pretty sure it’s because self.a and self.b are still LazyMedia or whatever - a link to the table which downloads every time the link is tapped. Is there a way to store the image on the browser/client-side so it’s ready to go immediately?

Thanks!
Bruce

Solved! The solution for anyone also wondering/future questions:
Use get_bytes() to get the object onto client side, then convert back into media. For one of my pictures:

self.a = app_tables.temp_counts.get(uid='1')['picture'].get_bytes()
self.a = anvil.BlobMedia(content_type="image/png", content=self.a, name="pic.png")

Absolutely instantaneous now!

B

1 Like

How about Adding your own asset files?

This would work if all the images come from you, and are all fixed in advance.

If the images are in a table because other people or processes will be creating them, or revising their contents, then a table remains the better solution.