Link needs two clicks - anvil.server.get_api_origin() + '/path'

Hi all,

When I use:
anvil.server.get_api_origin() + '/path' in the following app, I have to click the link twice before the media returns. However, if I paste in the actual URL that the IDE gives me, I only have to click the link once, and I “get the goods”.

Is there a way to return the media from the http endpoint with one click (note that the link’s url is assigned after the click).

https://BFM4ZL4RS3X3QJOQ.anvil.app/PY27AZCXKDV46HCWJRKF2V7D

Hi @alcampopiano! Did you mean to share a clone link to the app rather than its URL?

My apologies. Here is the clone link:
https://anvil.works/build#clone:BFM4ZL4RS3X3QJOQ=A4HF3KVZYN7CAZZQDG5A6IVM

Have you tried calling get_api_origin in the __init__ method rather than the click handler?

  def __init__(self, **properties):
    self.init_components(**properties)

    self.link_1.url = anvil.server.get_api_origin() + '/path'
    self.label_1.text = anvil.server.get_api_origin() + '/path'

Here’s a clone link with your code modified to do that:

https://anvil.works/build#clone:DXDEDQ6KSCQAZODP=HKUEHKATXGUB7PP74LZCO7CU

Also, you may be able to use the new download function to avoid the need for an API endpoint.

1 Like

Thanks @shaun. The new download function meets my needs perfectly. I just love that I can trigger a download this easily. It has already made a big difference in an application that is essential to staff here. Thanks very much.