Trying to upload an image to self_image_1 from the client Python script

What I’m trying to do:

I want to allow the external (client-side) Python script to read in an image (via code) that is stored locally on their device and use that image as the source for self.image_1 on the Anvil Web App. How should I go about the code on both the client script and the Anvil script for this? I’m very new to Python so I’d really appreciate the help!

1 Like

Just for clarity, you are trying to use external python code and not the anvil’s client python code right?

Correct, I’m trying to call the image file (.png) from the external Python code.

I will give you key pointers to look at before actually putting the code.

You need to research about HTTP and how do you send data from client using this HTTP(data being json,files like images/pdf etc.)

Then you need to research about REST API, which is destination for HTTP.

Anvil’s server code would be acting as REST API, to which you will connect your client via HTTP.

Having received data(image) at Anvil server, you set that image to source of Anvil Image added at webapp side

Actually, Anvil provides a very handy shortcut, Uplink: Code outside Anvil, that bypasses any need to know about HTTP and REST APIs.

2 Likes

@p.colbert Absolutely correct, uplink is better option considering @udayt is using python itself for client code.

Http endpoint is generalised, so if in future @udayt needs to change client (like using angular,react etc) then he just need to call http endpoint as these technologies don’t support uplink.

Please correct me if I am wrong :upside_down_face:

@Aditya_Kawale, you have a very good point. Future uses, if known, should be factored in.

1 Like