Caching issue with new file uploader


I just updated the new uploader and now I get an error I did not get before when I try to pass my uploaded csv file to a cached function.

I looked at the documentation of the file uploader and tried to convert the uploaded object in something else with StringIO(uploaded_file.decode(“utf-8”)) and with text_io = io.TextIOWrapper(uploaded_file) but I still get the caching error.

I assume I need to add something to my cache function. I have tried @st.cache(hash_funcs={StringIO: StringIO.getvalue}) and others but it does not work.

Being trying to solve this for some time. Help is really appreciated :slight_smile: Great product!



Hello again,

I am still having difficulties using the cache with the new file uploader. This must be really easy but I am stuck since three days…

I have a function that allows the user to either choose a local file or upload her own.

This function passes the path of the local file (if local file chosen) or the StringIO (if upload) object to a the cached function that pd.read_csv reads dataset into a dataframe.

When I load a local csv dataset the cache works, while when I load the file with the file uploader the cache does not work because it sees a “change” in the input. I noticed that the the “number” of the BytesIO changes, so there is a different output from the file uploader.


I take the output of the file uploader (a csv file) and transform it like so:

    uploadedFile =
    uploadedFile = BytesIO(uploadedFile)

And then I pass the result to a pd.read_csv file.

With the previous file uploader I passed the output of the file uploader that now looks like this
to the cached function and it worked perfectly.

Now if I try to pass the output without transforming it I get this cache error.

I have also tried wrapping the uploaded object in TextIOWrapper


but I get a similar “do not know what to cache” error

I am running in circles. I understand that the solution must be obvious :slight_smile:
Many thanks for your help


If this helps anybody. It is .getvalue() not .read()


Glad you got it figured out @Fabio!

more precisely it is

        bytesData = uploadedFile.getvalue()
        encoding = 'utf-8' 
        result = StringIO(s)