Displaying images from web2py as a server

42 views
Skip to first unread message

mostwanted

unread,
Oct 9, 2023, 12:56:05 AM10/9/23
to web2py-users
I have a little functionality here where i'm pulling information from a web2py server and displaying it on a kivy app for the user, all the other details are displaying but the image is failing to display & I get the error: [ERROR  ] [AsyncImage  ] Not found <person.image.9c6d5fece48d877e.SU1HLTIwMjIwOTE2LVdBMDAwMC5qcGc=.jpg>.

What am I doing wrong? How do I get the image to display coz its clearly there?

WEB2PY CODE:
@request.restful()
def api_list_clients():
    def GET(*args, **vars):
        query = db().select(db.person.ALL)
        return response.json(dict(clients=query.as_list()))
    return locals()

KIVY CODE:
def read_from_server(self):
        self.root.ids.display_screen.clear_widgets()
        response = requests.get("http://localhost:8000/clients/default/api_list_clients")
        if response.status_code == 200:
            print("Response content:", response.content)
            try:
                data = response.json()
                clients = data.get("clients", [])
                for client in clients:
                    name = client.get("name")
                    surname = client.get("surname")
                    cell = client.get("cell")
                    email = client.get("email")
                    image_url = client.get("image") 
                    details_layout = BoxLayout(orientation='vertical', spacing=10)
                    name = MDLabel(text=name, halign="center")
                    surname=MDLabel(text=surname, halign='center')
                    cell=MDLabel(text=cell, halign='center')
                    email=MDLabel(text=email, halign='center')
                    details_layout.add_widget(name)
                    details_layout.add_widget(surname)
                    details_layout.add_widget(cell)
                    details_layout.add_widget(email)
                    image = AsyncImage(source=image_url)
                    details_layout.add_widget(image)
                    self.root.ids.display_screen.add_widget(details_layout)
            except json.JSONDecodeError as e:
                print("Error parsing JSON response:", e)
        elif response.status_code == 204:
            # Handle empty response (No Content)
            print("No clients found.")
        else:
            print("Failed to read from server. Status code:", response.status_code)

CarlosDB

unread,
Oct 10, 2023, 8:56:16 AM10/10/23
to web2py-users
In your example, `image_url` is not the URL of the image, it's the value of the "upload" field.

Try something similar to this:
image = AsyncImage(source=f"http://localhost:8000/download/{image_url}")

Carlos.
Reply all
Reply to author
Forward
0 new messages