AttributeError: 'UploadedFile' object has no attribute 'get_value'

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:

  1. AttributeError: ‘UploadedFile’ object has no attribute ‘get_value’
  2. 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

The methods are getbuffer() and getvalue(), without the underscore.

@edsaac Welp, I’m an absolute genius. Thanks for your help.

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