Serving images through URLs

Okay, well using http requests I can render an image from a string returned from hitting an endpoint.

Clone for the app that is hosting images:
https://anvil.works/build#clone:JBZ2GLLBF4TWOJ4Z=K4MQJPIL3IE3FTGYW3XNVGE4

Relevant code:

# this returns the url through an endpoint as a string
@anvil.server.http_endpoint('/get_url')
def get_url():
  
  im=app_tables.my_images.get(name='cat1')['image']
  return im.url

Clone for the app that is getting images (from hitting the other app’s endpoint):
https://anvil.works/build#clone:5C6DM5UMF3POGDZ4=3O3U774QF6HSIZDPNM3EB6M6

Relevant code:

# this gets the url of the image by hitting the host's endpoint
@anvil.server.callable
def hit_endpoint():
  resp = anvil.http.request("{my_url}/get_url")

  return str(resp.get_bytes(),  'utf-8')

Perhaps there is a better way of doing this but I am making use of Anvil’s HTTP request to hit the endpoint. The endpoint returns a string to the calling app, and that string is the “source” for the Image component. Seems to work on my end.

1 Like