Read png from s3 using st.connection

Hi folks

I am facing a bug with my connection between Streamlit and aws s3
here I share my code snipped

conn = st.connection('s3', type=FilesConnection)
file_stream = conn.read(f"virgo-data/market_plots/{symbol_name}/{name}", input_format="png", ttl=30)
fig = Image.open(file_stream)
st.image(fig)

my goal is to read one png or jpeg file stored in S3 and display it in my app deployed in the community cloud.

I have been working with this type of connection for a while with other type of data formats such as json, csv and it is working fine

I will appreciate your help!
thanks!

1 Like
  • What is the error message?
  • Could file_stream be read?

Hello Franky and thanks for contacting me

yes the error is

png is not a valid value for input_format=

Indeed, png is not valid:

However, neither image nor binary formats seems to be valid.
I would try it with input_format=None if the path argument has .png as suffix and see what happensโ€ฆ


Edit: After looking at the implementation i donโ€™t think that any image or binary formats will workโ€ฆ

import streamlit as st
import s3fs

# AWS S3 bucket credentials are stored in secret file
fs = s3fs.S3FileSystem(anon=False)

# one can also directly give credentials
# fs = s3fs.S3FileSystem(anon=False, key="My-AWS-Key", secret="adsfgasdgag")

st.image(fs.open('my-bucket/assets/blah.png', mode='rb').read())