First - I am trying to read the docs and search this forum… some stuff is just elusive and likely due to my developing skill level - apologize.
Please explain the url - how do I specify a media object (.jpg) stored in a table, or do I have to do a full table lookup, etc. Is there an ‘internal’ url or something? Does this url point to an image stored somewhere in my app?
my_media = anvil.URLMedia(“https://anvil.works/ide/img/banner-100.png”)
You can store the image in a Media column, then access it with the url with something like:
app_tables.search(name='my image')['image'].url
Or, step by step:
row = app_tables.search(name='my image')
image = row['image']
url = image.url
Here is the documentation.
You can do it, but doesn’t mean you need to do it. If you need to access the image from inside Anvil, you don’t need to get the image, then get the url, then use the url to get the image back. You get the image and use it. Simple.
If you give us more details, we can try to help with your specific case.
from your other post (assuming it’s related)
Simplest image display option
For a single image (or a couple that you use throughout your project like logos etc) you can add these to your assets using the upload

The link to this image will be '_/theme/{Name of your file}'
Anvil Docs | Custom Styling
Testing this, but I have to do this from a servermodule I believe as my code is returning an error that searching a table cannot be performed from the client code. OK.
My specific question about URLMedia is how exactly, precisely, is the url (such as banner-100.png) determined/constructed? Does it have to be available out on the internet somewhere so Anvil can fetch it? This is why I thought storing the media in a table would be necessary/preferred.
What is the use case?
If it’s a single banner then I’d put it in assets and the url will be simple…
if it’s lots of images that you pull an image depending on parameter then use a table…
You could move @stefano.menci code to the server if your data table is private and call it from the client
You could also change the privacy settings and make the table viewable from the client if accessing this table from the client does not cause a security issue.
#server
@anvil.server.callable
def get_img_url(name):
return app_tables.search(name= name)['image'].url
# client
url = anvil.server.call('get_img_url', 'image_name')
I had not even read about or explored assets - I will. How do we pay back for the assistance here, is there someplace to contribute or something?
This forum is a friendly place and many of us enjoy helping whenever possible.
Perhaps just tell others about Anvil if you enjoy using it as we do.
2 Likes
The default settings don’t allow client code to see your tables. You can change a table settings and make it read and write, read only or not visible to the client code.
For a quick test you can set your table writable from the client, so you can quickly get something running. But now any hacker can see and modify your table.
The correct way from the point of view of safety and performance is to create a server function that collects whatever the client needs and return it at once. If you need to return an image to show on a form you can return the media object, better than returning the url to the client and making another round trip to get the image.
1 Like