# Uploading, downloading files and equations in text

**URL:** <https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687>\
**Category:** Deployment\
**Tags:** file-download, heroku, file-upload\
**Created:** [October 23, 2019, 3:26pm UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687 "2019-10-23T15:26:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emmanuel\_Pean](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/emmanuel_pean/32/48875_2.png) [@Emmanuel\_Pean](https://discuss.streamlit.io/u/Emmanuel_Pean)\
**Post date:** [October 23, 2019, 3:26pm UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/1 "2019-10-23T15:26:30Z")

</div>

Hi. I discovered streamlit last week and enjoyed working with so much that I ended up writing a small app for fitting experimental data.

However, there are a few things that the app is missing before I can make it available to everyone:

- First thing is a file uploader from the client to the server (so the users can upload their own data that the app then reads). I believe this is work in progress ([https://github.com/streamlit/streamlit/issues/120](https://github.com/streamlit/streamlit/issues/120)) so I just need to be patient.
- I want the user to be able to download the output data from the fitting. I’ve managed to store the data in a file on the Heroku server where my app is working on, however, I’m not sure how to create a download link for the file.
- Last thing, it would be great if we could display simple math equations, not only in streamlit.text but also streamlit.selectbox although that is not very important for now in my case.

Thanks a lot for your help and suggestions.

---

<div class="post-metadata">

**Author:** ![mdav](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/mdav/32/637_2.png) [@mdav](https://discuss.streamlit.io/u/mdav)\
**Post date:** [October 23, 2019, 5:18pm UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/2 "2019-10-23T17:18:24Z")

</div>

Definitely agree here! Right now I’m having the users enter the email address, and then receive the data via email (or worse, copy and paste the dataframe if it’s small enough).

It would be so great if the users could simply download the data directly from the browser!

---

<div class="post-metadata">

**Author:** ![tim](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/tim/32/101_2.png) [@tim](https://discuss.streamlit.io/u/tim)\
**Post date:** [October 31, 2019, 4:23pm UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/3 "2019-10-31T16:23:05Z")

</div>

Hello, @Emmanuel_Pean! Welcome to Streamlit, and thanks for your suggestions!

1. Yeah - as you noted, we’re working on a [File Uploader Widget](https://github.com/streamlit/streamlit/issues/120) that will be released in a couple of weeks. (This has been a very frequent feature request, so we’re prioritizing it.)
2. Streamlit does not have a way to serve file downloads. We’re [tracking that request at this Github issue](https://github.com/streamlit/streamlit/issues/400) - please feel free to thumbs-up the issue if it’s important to you; we take user demand into consideration when prioritizing new feature development!
3. [LaTeX support was just merged into Streamlit!](https://github.com/streamlit/streamlit/issues/296) This will go out in a Streamlit release in a couple weeks as well. (You can also use the [Streamlit `develop` branch directly](https://github.com/streamlit/streamlit/tree/develop) if you want to use features that have been finished but not yet released to PyPI.)

As a workaround for file download support, here’s a Gist that demonstrates patching Streamlit to allow static file downloads: [https://gist.github.com/tconkling/1e5ead87c796a82de7fa71fcc4a74777](https://gist.github.com/tconkling/1e5ead87c796a82de7fa71fcc4a74777). (And of course, it probably goes without saying, but you want to be very careful about what resources you expose to the internet!)

Cheers!

---

<div class="post-metadata">

**Author:** ![Emmanuel\_Pean](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/emmanuel_pean/32/48875_2.png) [@Emmanuel\_Pean](https://discuss.streamlit.io/u/Emmanuel_Pean)\
**Post date:** [October 31, 2019, 5:37pm UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/4 "2019-10-31T17:37:42Z")

</div>

Hi @tim,

Great, I look forward to see (1) and (3) implemented in streamlit!  
Thanks for the link to the request for downloading files. I’ve modified the side-packages/streamlit/server/Server.py file using the gist you provided, however, when I try to run the app locally, it just doesn’t display anything anymore (the page is completely blank).  
Any idea what is the problem?

Cheers,

Emmanuel

---

<div class="post-metadata">

**Author:** ![tim](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/tim/32/101_2.png) [@tim](https://discuss.streamlit.io/u/tim)\
**Post date:** [October 31, 2019, 6:00pm UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/5 "2019-10-31T18:00:54Z")

</div>

Whoops, looks like I forgot to note that you also need to add `import os` to `Server.py`, before the `TORNADO_SETTINGS` dict. I’ve updated the gist - can you give that a try?

If it doesn’t work, can you paste any console output that you get from `streamlit run ...`? I’ve tested this locally, but not extensively across different OSs and Python versions.

---

<div class="post-metadata">

**Author:** ![Emmanuel\_Pean](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/emmanuel_pean/32/48875_2.png) [@Emmanuel\_Pean](https://discuss.streamlit.io/u/Emmanuel_Pean)\
**Post date:** [October 31, 2019, 7:09pm UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/6 "2019-10-31T19:09:56Z")

</div>

I’m not getting any error message when running the app locally. I did a few tests and here’s what I found: It works after I add `"static_path": os.path.join(os.getcwd(), "static")` to the dict. After a few minutes, if I reload the app, it just load a blank page. If I comment `"static_path": os.path.join(os.getcwd(), "static")` and re-run the app locally, it works again.

UPDATE: It seems to working fine now locally (no idea why how it fixed itself though). However, I can’t manage to download the test file I put in the static folder after uploading the app on Heroku. I use `https://appname.herokuapp.com:80/static/testfile` and I get a `ERR_SSL_PROTOCOL_ERROR` error message after a few seconds.

---

<div class="post-metadata">

**Author:** ![jamestjw](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/jamestjw/32/622_2.png) [@jamestjw](https://discuss.streamlit.io/u/jamestjw)\
**Post date:** [November 6, 2019, 8:44am UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/7 "2019-11-06T08:44:20Z")

</div>

I can confirm that changing that line in the `Server.py` file causes Streamlit to just load a blank page, and commenting it out causes it work fine again. I was working in Python3.7.4 on Catalina 10.15.

---

<div class="post-metadata">

**Author:** ![tim](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/tim/32/101_2.png) [@tim](https://discuss.streamlit.io/u/tim)\
**Post date:** [November 6, 2019, 4:51pm UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/8 "2019-11-06T16:51:46Z")

</div>

Hey @jamestjw - just making sure you saw that there are two lines that need changing: a line to add the config option to `TORNADO_SETTINGS`, and also a line to `import os`.

(If you’re still seeing a blank page after that, could you paste the Streamlit output from your terminal?)

---

<div class="post-metadata">

**Author:** ![jamestjw](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/jamestjw/32/622_2.png) [@jamestjw](https://discuss.streamlit.io/u/jamestjw)\
**Post date:** [November 7, 2019, 3:14am UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/9 "2019-11-07T03:14:11Z")

</div>

Well, that’s just it, there is no visible error message or anything. I’m a little unsure what’s going on here, but as soon as I comment out that line in the TORNADO\_SETTINGS, things start working again. And yes I also imported `os`.

 ![image](https://global.discourse-cdn.com/streamlit/original/1X/00c9b2b5a449c35377d0ebe125cc66b6ea5231c8.jpeg)

Quick update: Blank page situation happens on safari, but not in Chrome. However, when I use the network URL instead of the local URL, the problem occurs on all browsers.

---

<div class="post-metadata">

**Author:** ![monchier](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/monchier/32/112_2.png) [@monchier](https://discuss.streamlit.io/u/monchier)\
**Post date:** [November 13, 2019, 7:58pm UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/10 "2019-11-13T19:58:03Z")

</div>

I am trying out this as well, and I am finding the same problem. I am able to download a static file, but the page just stays blank. By looking at the network tab it seems that all assets that were being fetched on `static` originally returns 404. Likely, the new setting is conflicting.

I am going to do some debug on this and see what I can find…

Best,

Matteo

---

<div class="post-metadata">

**Author:** ![monchier](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/monchier/32/112_2.png) [@monchier](https://discuss.streamlit.io/u/monchier)\
**Post date:** [November 13, 2019, 9:15pm UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/11 "2019-11-13T21:15:50Z")

</div>

This is what I came up with:

> <https://gist.github.com/monchier/b3c200a002f8030db07fa72f8827f10f>

This gist is a patch to `Server.py` that adds an endpoint called `text`. This endpoint points at a static file in a local directory called `custom_static`.

Of course, this is kind of a short term solution…  
The [github issue](https://github.com/streamlit/streamlit/issues/400) seems to have other proposals to do this as well.

Matteo

---

<div class="post-metadata">

**Author:** ![Emmanuel\_Pean](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/emmanuel_pean/32/48875_2.png) [@Emmanuel\_Pean](https://discuss.streamlit.io/u/Emmanuel_Pean)\
**Post date:** [November 15, 2019, 12:58pm UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/12 "2019-11-15T12:58:04Z")

</div>

The app seems to work well locally and on Heroku with this patch however, I still can’t download the test file using [https://appname.herokuapp.com/:8501/custom\_static/text](https://appname.herokuapp.com/:8501/custom_static/text). Is the link I’m using wrong?

---

<div class="post-metadata">

**Author:** ![monchier](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/monchier/32/112_2.png) [@monchier](https://discuss.streamlit.io/u/monchier)\
**Post date:** [November 15, 2019, 5:06pm UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/13 "2019-11-15T17:06:03Z")

</div>

@Emmanuel_Pean, with the patch I gave you, the link would be [https://appname.herokuapp.com/:8501/text](https://appname.herokuapp.com/:8501/text)

Unsure your address is correct, but what I mean, you don’t have to add `custom_static`. You can change this behavior by changing [line 26 of my patch](https://gist.github.com/monchier/b3c200a002f8030db07fa72f8827f10f#file-server-py-patch-L26). You need to change the matching regex that is the first element of the tuple on that line.

Matteo

---

<div class="post-metadata">

**Author:** ![Emmanuel\_Pean](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/emmanuel_pean/32/48875_2.png) [@Emmanuel\_Pean](https://discuss.streamlit.io/u/Emmanuel_Pean)\
**Post date:** [November 18, 2019, 11:26am UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/14 "2019-11-18T11:26:17Z")

</div>

Hi @monchier, thanks for your reply.  
It’s working locally but not on Heroku (here’s the link to my app [https://trpl-fit-tool.herokuapp.com/](https://trpl-fit-tool.herokuapp.com/)).

Emmanuel

---

<div class="post-metadata">

**Author:** ![monchier](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/monchier/32/112_2.png) [@monchier](https://discuss.streamlit.io/u/monchier)\
**Post date:** [November 18, 2019, 9:39pm UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/15 "2019-11-18T21:39:27Z")

</div>

Interesting, I am not a Heroku expert, but here is what I can see from quickly looking at the app you published:  
This link [http://localhost:8501/text](http://localhost:8501/text) will not work because it is referring to `localhost` which is your local machine.  
About your second link. There might be a problem is with `/:8501`. You are publishing your app on port `80`, so no need to give it the Streamlit port number. Heroku will transalte that for you. Also, you should not be using the `/` before the port number in any case. I would say this should work: [http://trpl-fit-tool.herokuapp.com/text](http://trpl-fit-tool.herokuapp.com/text), but when I try it in my browser it does not. There might be an extra configuration step on the Heroku side that is needed. Can you also double check you have deployed the text file in your Heroku container and that is in the right directory?

Note that I also haven’t used `https` here. Not sure how you have configured that, but I am not sure there is some extra step in configuring Heroku to get it to work with `https`. You can try both version in any case.

Best  
Matteo

---

<div class="post-metadata">

**Author:** ![Emmanuel\_Pean](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/emmanuel_pean/32/48875_2.png) [@Emmanuel\_Pean](https://discuss.streamlit.io/u/Emmanuel_Pean)\
**Post date:** [November 19, 2019, 10:45am UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/16 "2019-11-19T10:45:58Z")

</div>

According to the Heroku docs, `https` is activated by default so you can access the app with `https://trpl-fit-tool.herokuapp.com/`. The file is definitely on the server, however, I have no idea how to configurate the server so that the file can be dowloaded.

Emmanuel

---

<div class="post-metadata">

**Author:** ![monchier](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/monchier/32/112_2.png) [@monchier](https://discuss.streamlit.io/u/monchier)\
**Post date:** [November 21, 2019, 1:48am UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/17 "2019-11-21T01:48:41Z")

</div>

Hi @Emmanuel_Pean, unfortunately that’s about the extent of my knowledge of Heroku, but if anyone in the community wants to weigh in we’d love that. Also, it won’t be ready until early next year but deploying apps through Streamlit is going to be a component of our For Teams offering. If you’d like to sign up for more information here is a link: [https://streamlit.io/forteams/](https://streamlit.io/forteams/)

Best,  
Matteo

---

<div class="post-metadata">

**Author:** ![Marc](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/marc/32/602_2.png) [@Marc](https://discuss.streamlit.io/u/Marc)\
**Post date:** [December 4, 2019, 11:17am UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/18 "2019-12-04T11:17:41Z")

</div>

Hi All

I’ve discovered a workaround for downloading small files from streamlit.

I’ve added it to the gallery at [awesome-streamlit.org](http://awesome-streamlit.org/). It’s called “File Download Workaround”. You can try it out and copy the code.

 ![file_download_workaround](https://global.discourse-cdn.com/streamlit/original/1X/ae82d022268b355b8c4c63e1b2ac3c2f4ef02234.gif)

---

<div class="post-metadata">

**Author:** ![Emmanuel\_Pean](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/emmanuel_pean/32/48875_2.png) [@Emmanuel\_Pean](https://discuss.streamlit.io/u/Emmanuel_Pean)\
**Post date:** [December 4, 2019, 11:47am UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/19 "2019-12-04T11:47:15Z")

</div>

Kudos! It works perfectly!  
May I ask what is the maximum file size or string length that can be downloaded with this method?

---

<div class="post-metadata">

**Author:** ![Marc](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/marc/32/602_2.png) [@Marc](https://discuss.streamlit.io/u/Marc)\
**Post date:** [December 4, 2019, 12:06pm UTC](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687/20 "2019-12-04T12:06:14Z")

</div>

I would not know. At first I thought it would be small. But I can see this site [https://www.base64encode.org/enc/length/](https://www.base64encode.org/enc/length/) has a limit of 192MB!

 ![image](https://global.discourse-cdn.com/streamlit/original/1X/716ac27aae5204265b9a7036ef9f11c5bf23d482.png)

According to [https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics\_of\_HTTP/Data\_URIs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) Firefox supports unlimited length in theory.

 ![image](https://global.discourse-cdn.com/streamlit/original/1X/82efb52b25cbd65caf7b6637644b1de2e57b7a56.png)

[Next page](https://discuss.streamlit.io/t/uploading-downloading-files-and-equations-in-text/687.md?page=2)
