Trouble in showing image from google drive url

If you’re creating a debugging post, please include the following info:

  1. I am running both app locally and deployed. Python version 3.9.4, streamlit 1.30.

2.My code

import streamlit as st

# iamge ID
file_id = "1A77PZeaLXZXDDzBNTPJZ-dxHd4DUAMx0"

# URL
url = f"https://drive.google.com/uc?export=view&id={file_id}"

# show image
st.image(url)

Hope anyone can give me how to manage the trouble.
Thanks in advance!

1 Like

I don’t know why exactly it doesn’t work (maybe redirects?) but you can make it work using the requests library.

import requests
import streamlit as st

# iamge ID
file_id = "1A77PZeaLXZXDDzBNTPJZ-dxHd4DUAMx0"

# URL
url = f"https://drive.google.com/uc?export=view&id={file_id}"

response = requests.get(url)
st.image(response.content)

Of course you could use also urllib3 or the builtin urllib, but I know requests better.

1 Like

Dear Goyo,
Many thanks to your solution. It works with me!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.