# File upload

**URL:** <https://discuss.streamlit.io/t/file-upload/31267>\
**Category:** Using Streamlit\
**Created:** [September 28, 2022, 11:38am UTC](https://discuss.streamlit.io/t/file-upload/31267 "2022-09-28T11:38:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![neelakandan\_rakesh](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/neelakandan_rakesh/32/18383_2.png) [@neelakandan\_rakesh](https://discuss.streamlit.io/u/neelakandan_rakesh)\
**Post date:** [September 28, 2022, 11:38am UTC](https://discuss.streamlit.io/t/file-upload/31267/1 "2022-09-28T11:38:57Z")

</div>

I’m trying to create an uploader file that works as input for all my tabs.  
please help me how to do it.

sample code:  
selected = option\_menu(None, [“Home”, “Upload”, “Tasks”, ‘Settings’],  
icons=[‘house’, ‘cloud-upload’, “list-task”, ‘gear’],  
menu\_icon=“cast”, default\_index=0, orientation=“horizontal”)  
selected

if selected == “Home”:  
st.title(f"You have selected {selected}“)  
if selected == “Upload”:  
st.title(f"You have selected {selected}”)  
with st.header(‘1. Upload your CSV data’):  
uploaded\_file = st.file\_uploader(“Upload your input file”, type=[‘csv’])  
if selected == “Tasks”:  
#st.title(f"You have selected {selected}")  
### Read csv  
iris = pd.read\_table(uploaded\_file , sep=‘,’, header=0)

---

<div class="post-metadata">

**Author:** ![Goyo](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/goyo/32/28219_2.png) [@Goyo](https://discuss.streamlit.io/u/Goyo)\
**Post date:** [September 28, 2022, 12:33pm UTC](https://discuss.streamlit.io/t/file-upload/31267/2 "2022-09-28T12:33:31Z")

</div>

Try this:

1. Assign an explicit key to the file uploader.  
`st.file_uploader("Upload your input file", type=["csv"], key="uploaded_file")`

2. Use `session_state["uploaded_file"]` to access the uploaded file where you need it.  
`iris = pd.read_table(st.session_state["uploaded_file"] , sep=",", header=0)`

I never tried this with a file uploader but it works with other widgets.

---

<div class="post-metadata">

**Author:** ![neelakandan\_rakesh](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/neelakandan_rakesh/32/18383_2.png) [@neelakandan\_rakesh](https://discuss.streamlit.io/u/neelakandan_rakesh)\
**Post date:** [September 29, 2022, 7:21am UTC](https://discuss.streamlit.io/t/file-upload/31267/3 "2022-09-29T07:21:13Z")

</div>

> [@Goyo](#):
>
> iris = pd.read\_table(st.session\_state[“uploaded\_file”] , sep=“,”, header=0)

wonderful Goyo this worked thanks

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/streamlit/original/3X/c/f/cf4c2ee0d938358f82448c5fe4b9c3c91d7ce19c.svg) [@system](https://discuss.streamlit.io/u/system)\
**Post date:** [September 29, 2023, 7:21am UTC](https://discuss.streamlit.io/t/file-upload/31267/4 "2023-09-29T07:21:29Z")

</div>

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