Skip to content

file_download class

Allows downloading of a file content.

Methods

__init__()

__init__(
    content=None,
    label=None,
    on_action=None,
    auto=False,
    render=True,
    bypass_preview=True,
    name=None,
    width=None,
    active=True,
    id=None,
    properties=None,
    class_name=None,
    hover_text=None,
) -> None

Create a new file_download element.

Parameters:

Name Type Description Default

content

Union[path,file,URL,ReadableBuffer,None]
dynamic

The content to transfer.
If this is a string, a URL, or a file, then the content is read from this source.
If a readable buffer is provided (such as an array of bytes...), and to prevent the bandwidth from being consumed too much, the way the data is transferred depends on the data_url_max_size parameter of the application configuration (which is set to 50kB by default):

  • If the buffer size is smaller than this setting, then the raw content is generated as a data URL, encoded using base64 (i.e. "data:<mimetype>;base64,<data>").
  • If the buffer size exceeds this setting, then it is transferred through a temporary file.

If this property is set to None, that indicates that dynamic content is generated. Please take a look at the examples below for more details on dynamic generation.

None

label

str
dynamic

The label of the button.

None

on_action

Union[str, Callable]

A function or the name of a function that is triggered when the download is terminated (or on user action if content is None).
This function is invoked with the following parameters:

  • state (State): the state instance.
  • id (str): the identifier of the button if it has one.
  • payload (dict): the details on this callback's invocation.
    This dictionary has two keys:
    • action: the name of the action that triggered this callback.
    • args: a list of two elements: args[0] reflects the name property and args[1] holds the file URL.
None

auto

bool

If True, the download starts as soon as the page is loaded.

False

render

bool
dynamic

If True, the control is displayed.
If False, the control is not displayed.

True

bypass_preview

bool

If False, allows the browser to try to show the content in a different tab.
The file download is always performed.

True

name

str

A name proposition for the file to save, that the user can change.

None

width

Union[str, int]

The width of the element.

None

active

bool
dynamic

Indicates if this component is active.
An inactive component allows no user interaction.

True

id

str

The identifier that is assigned to the rendered HTML component.

None

properties

dict[str, Any]

Bound to a dictionary that contains additional properties for this element.

None

class_name

str
dynamic

The list of CSS class names that are associated with the generated HTML Element.
These class names are added to the default taipy-file_download class name.

None

hover_text

str
dynamic

The information that is displayed when the user hovers over this element.

None