Skip to main content
Version: 0.2.0

PlainDownloader

ClassComponentSource

comp = PlainDownloader(
id: str | Mapping[str, Any],
url: str,
loading_state: LoadingState
)

PlainDownloader is a plain and native React component.

This component is implemented by a temporarily created magic link referring to a given URL.

Since the implementation of this PlainDownloader is simply based on the HTML <a> tag, the request headers and authentication of this downloader is not customizable.

Aliases

This type can be acquired by

import dash_file_cache as dfc


dfc.PlainDownloader
dfc.components.PlainDownloader

Component Properties

NameType
Description
idstr | Mapping[str, Any]The ID of the component. A dictionary-id is used for creating a pattern-matching callback.
urlstr

The URL used to access the data to be downloaded.

Each time when this value is set, a download event will be triggered. After triggering the download event, this value will be reset by a blank string.

loading_stateLoadingStateThe loading state set by Dash. This value should not be used by users.

Examples

Minimal example

minimal_example_plain_downloader.py
from typing import Optional
import dash
import flask
from dash import html, Output, Input
from dash_file_cache.services.utilities import get_server
from dash_file_cache.components import PlainDownloader


app = dash.Dash("demo")
server = get_server(app)

app.layout = html.Div(
(html.Button(id="btn", children="Download"), PlainDownloader(id="downloader"))
)


@server.route("/file")
def file():
resp = flask.Response("test file content", status=200, mimetype="text/plain")
resp.headers["Content-Disposition"] = "attachment; filename=test.txt"
return resp


@app.callback(Output("downloader", "url"), Input("btn", "n_clicks"))
def trigger_get_file(n_clicks: Optional[int]):
if not n_clicks:
return dash.no_update
return "/file"


if __name__ == "__main__":
app.run()