Summary
Python’s BytesIO
methods are not callable on UploadedFile
objects, even though UploadedFile
inherits from BytesIO
. I ultimately want to save uploaded files to disk, which I think requires get_value()
or get_buffer()
. What mistake am I making here?
Steps to reproduce
EXAMPLE 1: myFile.get_value()
import streamlit as st
with st.form("my_form"):
myFile = st.file_uploader("Image File")
submitted = st.form_submit_button("Upload")
if submitted:
st.write(myFile)
st.write(type(myFile.get_value()))
EXAMPLE 2: myFile.get_buffer()
import streamlit as st
with st.form("my_form"):
myFile = st.file_uploader("Image File")
submitted = st.form_submit_button("Upload")
if submitted:
st.write(myFile)
st.write(type(myFile.get_buffer()))
Actual behavior:
- AttributeError: ‘UploadedFile’ object has no attribute ‘get_value’
- AttributeError: ‘UploadedFile’ object has no attribute ‘get_buffer’
Debug info
- Streamlit version: 1.20.0
- Python version: 3.10.8
- Using Mamba 1.3.1, Conda 23.1.0
- OS version: Ubuntu 22.04.2 LTS
- Browser version: Firefox 113.0.2