dcc.Download not downloading large files

Hi,

I am new to Dash. I am creating an application where I need to download large files. I tried using dcc.Download. This components works well with small size files (upto ~300 MB). However, when I try to download large files (around ~ 500 MB) this component never downloads the file. As a check I also tried adding a dcc.Loading component to check if download is complete (dcc.Loading will change its message when download completes). For large files text of dcc.Loading also never gets updated. Would appreciate any help with this issue.

Following is the code I used:

import io
from os import close
import dash
from dash.dependencies import Output, Input
import dash_html_components as html
import dash_core_components as dcc

import matplotlib.pyplot as plt
import zipfile
from io import BytesIO

app = dash.Dash(prevent_initial_callbacks=True)
app.layout = html.Div([html.Button("Download zip", id="btn_txt"),
                       dcc.Loading(
                           id="loading-control",
                           type="default",
                           fullscreen=False,
                           children=[
                               html.Div("Requesting file", id="loading-child"),
                           ]
                       ),
                       dcc.Download(id="download-zip")]
                      )


@app.callback(
    [
        Output("download-zip", "data"),
        Output("loading-control", "children")
    ],
    Input("btn_txt", "n_clicks"),
    prevent_initial_call=True,
)
def func(n_clicks):
    file_path = "C:\\LargeFile.zip"
    return dcc.send_file(file_path, "Large File.zip"), ["File downloaded"]


if __name__ == "__main__":
    app.run_server(debug=False)

Thanks in advance.

1 Like

Hi! If you have solved the problem, please write how exactly. Because I have the same problem

Hello @Volodia,

I’d recommend using a background callback for this, it seems like the request may be timing out before it receives as valid response.

Hi - I have exactly the same problem. Small files get download and for larger files I get a “connection closed” error. It seems it just times out.
I tried using background callback and it seems to have no effect. Still get the same error.
Any solutions / workarounds much appreciated.