Uploading images to GCS using Streamlit FilesConnection

Hi all,

I’m new to Streamlit and would very much appreciate your help! I am building an app that lets users upload images to GCS.
I set up a bucket on GCS and followed the excellent guide in Here to connect my Streamlit app with the bucket.
I’m having trouble uploading the images, though. Is there any way to upload images using Streamlit FilesConnection? The only file formats I could see are text and parquet. Is there a way to take a jpeg image and save it in a parquet format?

Thanks in advance,
NC

I guess using conn.open() with mode="wb" to create the file and then writing the bytes to it should work. You might as well get rid of FilesConnection, since gcsfs already provides that kind of API.

Thanks for answering Goyo! The problem is that, afaiu, the only binary format supported by FilesConnection (using conn.open(), conn.read(), …) is parquet, and I’m not sure how it can help me deal with jpeg images.
One tning I forgot to mention is that I’m using a private bucket on GCS.

Your comment about using direct interface of gcsfs sounds interesting - do you have a good example of how to do that with streamlit?

Thanks,
NC

No, conn.open() returns a file-like object that allows you to read and write bytes, the format shouldn’t matter.

There are examples. I think you can just do something like this:

with open(source_path, mode="rb") as f:
    content = f.read()
with fs.open(destination_path, mode="wb") as f:
    f.write(content)

Thanks, I got it to work eventually by using Pd2Img - pd2img · PyPI