Upload Files to Streamlit App

Hi all,

I was wondering if there was a way to have a user upload a file (ie a txt or csv file) to a Streamlit app? I didn’t see anything in the docs about this.

Tangent from this, is it possible to inject HTML into Streamlit to create new functionalities?


Hi Karl.

Great questions!

#1: How to create a file selector

Currently, there is no file picker, but I just added a feature request for one. Please feel free to follow this request on Github to follow its progress.

In the meantime, here’s an example of a janky ad-hoc file selector on the server:

import streamlit as st
import os

filename = st.text_input('Enter a file path:')
    with open(filename) as input:
except FileNotFoundError:
    st.error('File not found.')

#2: How to inject custom HTML into Streamlit

What would you like to add? Streamlit already supports many different elements and we’re adding more each day. If you share some details we can help you achieve your aim.

In the long run, we plan to expose a plug-in architecture. I’ve created this tracking bug. Please feel free to add comments describing what you’d like to see here.


In general, please feel free to submit bug report or feature requests at our repo.


Here’s another, perhaps slightly less janky ad-hoc file selector on the server:

import streamlit as st
import os

def file_selector(folder_path='.'):
    filenames = os.listdir(folder_path)
    selected_filename = st.selectbox('Select a file', filenames)
    return os.path.join(folder_path, selected_filename)

filename = file_selector()
st.write('You selected `%s`' % filename)

And here’s what it looks like:

Of course, these file selectors can be improved a lot, but these examples illustrate that fairly complex and useful UIs can be built using existing Streamlit primitives.


Thanks Adrien!

As for the HTML, I just thought that would be a quick way to add functionality that isn’t officially supported. For example a HTML element could help handle the scenario of a user uploading a file (imagine the case where the Streamlit app is hosted on AWS while the file is on a local directory).

1 Like

Good point. These are file selectors on the server. I will update the feature request to reflect that. Thanks, Karl!

1 Like

Thank you @Adrien_Treuille. How about more of a dialogue box? That way the user can go back and into subfolders?

1 Like

Salim. Yes. The code we shared is a workaround for now. We will have to implement this feature request before you can get a full dialog. Please follow that request to get updates on when we implement it.

p.s. To help us do so quickly, could you please let us know if you would like:

  1. To upload a file on the client (where you access Streamlit)
  2. To upload a file on the server (where you ran streamlit run ...)
  3. Or are (1) and (2) the same for you?



Thanks @Adrien_Treuille, was looking to upload with the client for now.

Thanks again.


I too eagerly await the functionality of being able to have a file picker where a user could upload/select uploaded file more easily integrated.


I’ve been thinking about this more now that my front end is deployed. What’s Streamlit’s general philosophy for web based applications where there may be a need for a user to upload data for prediction and/or download results?

1 Like

Hey @karl,

For the uploader, we have this feature request, does this sound like it would be useful? For the downloader, we haven’t started a feature request for that yet, but we have been actively thinking about it, we’d love to get your input & ideas either here or through a new request on the GitHub.


Any update on this feature?

Hey @qxlsz and welcome to the community :wave:,

We’re actively working on this right now, and it’ll be coming out in the next couple of weeks :blush:! Here is a link to the pull request.


While I wait for the file uploader I’ve been able to add the functionality for my prototype, behind a firewall by running a seperate Droopy MiniServer

python droopy.py -d  /app/storage/ --publish-files 8503 &
streamlit run app.py

and then embedding the file upload in my streamlit app.py file as markdown with the unsafe_allow_html=True option.


sorry to bother you… i have copied the html … but it shows “405: Method Not Allowed”… why?

I prefer to have a user upload a text or csv file. Any Idea?

Hi @asghar3166 - the pull request that implements this feature will support uploading text and csv. It should be merged soon!

1 Like

Awaiting this feature would love to have it and apply it to my app.

The PR was merged :slight_smile:


Pardon my ignorance about how features are being developed and how updates are happening, but how will we get our hands on the file uploader?

  1. Is it already released in a branch which I can clone?
  2. When would it be available through the usual channels, like Pypi
  3. Can I find preliminary documentation for the uploader before it is officially released through the docs?

Thanks for your answer, Streamlit is awesome and I am really waiting for this feature!

1 Like