Displaying an image by URL

Hello,
According to the docs
This should work in order to display an image by url

my_media = URLMedia(“https://anvil.works/ide/img/banner-100.png”)
self.image_1.source = my_media

I tried with:
self.image_1.visible = True

but it also does not work,
what is the right way to display an image from remote url ?
(i return the url from a server module first, then want to display it to the user)

Thank you

Try this -

create a server module with this in :

import anvil.server
from anvil import URLMedia

@anvil.server.callable
def getimage():
  my_media = URLMedia('https://anvil.works/ide/img/banner-100.png')
  return my_media

Then in your client do this (for example) :

x = anvil.server.call('getimage')
self.image_1.source = x

On re-reading your question I may have misunderstood that you wanted to get the image from a server module, but I’m sure you can adapt to suit.

1 Like

(Admin note: This wasn’t to do with the original thread, so I’ve moved this out into a new topic!)

1 Like

Hey,

The two lines you quoted from the docs work for me, take a look at this app to see:

https://anvil.works/ide#clone:LGWB5DZDA6Q63CA3=GEBJL6XSEPAYBJ6XPSBEXFLZ

Perhaps the URL you are returning from your server module is not a string, but some other kind of object?

Would you care to share your app so I can take a look (or a simplified app that reproduces this issue, if you want to keep the rest of your app private)?