Adding images programmatically. How to make sure images are not backgrounds. for downloadability

What I’m trying to do:

I have created a gallery on my app which gets populated with images programmatically using link and image elements. images are served from a CDN.

What I’ve tried and what’s not working:
gallery and the images work fine.
problem is that the images are not downloadable(they are displayed as background) in mobile by click holding or on pc “save image as” does not appear on right click action.

I would very much appreciate if anyone can tell me how to make this work as it is essential to the app I am building.

I do not wish to have a button on the pop up to download because that downloads the image to the files and not to the photos unless I am missing something. This could be an option if anyone knows how to make sure a button from an alert will download images into photos app.

Code Sample:

# this is a formatted code snippet.
# paste your code between ``` 
for image in imgs[0:500]:
      link = Link()
      link.add_component(Image(source=URLMedia("https://*********.cloudfront.net/" + image), width=110, height=110))
      link.tag = "https://*********.cloudfront.net/" + image
      link.set_event_handler('click', self.link_click)
      self.gallery.add_component(link, width=110)
  def link_click(self, **event_args):
    # print("CLICK~")
    # test = event_args['sender']
    # print(test.tag)
    """This method is called when the link is clicked"""
    alert(
      Image(source=URLMedia(event_args['sender'].tag), height=512),
      buttons=[('Back', None, None)],
      large=True,
    )

Clone link:
share a copy of your app

There are a number of ways you could do this. I am a big fan of building forms that can be used inside alerts, this way the building of the alert doesnt have to be done from code.

I will knock up a quick example that uses this approach and has a download button.

How are you displaying the gallery before clicking on it?

Just to be clear, you want a gallery of images that can be viewed and downloaded?

EDIT: Hmmm not as easy as I thought. I see your conundrum. Every option that I try comes to the same issue where the image either gets saved to downloads or is not save able at all. I wonder if creating a HTML form would help…

https://anvil.works/build#clone:TPZ37ZXJ2AYXMRUZ=NT644UA7CTXEG6KRHFYBC3Q4

This is exactly what I’m looking for. Could you share the code for this?

Here are 2 useful ways: download image when clicked (using anvil.media.download and anvil.URLMedia), and open image in separate browser tab when link is clicked:

https://anvil.works/build#clone:QG6433KLAEILU77F=HVQQP4X2COHMI5T4THDXKM6K

1 Like