Skip to content

Taipy.gui.download

Download content to the client.

Parameters:

Name Type Description Default
state State

The current user state as received in any callback.

required
content Any

File path or file content. See below.

required
name Optional[str]

File name for the content on the client browser (defaults to content name).

''
on_action Optional[Union[str, Callable]]

Callback function (or callback name) to call when the download ends. See below.

''

Notes:

  • content: this parameter can hold several values depending on your use case:
    • a string: the value must be an existing path name to the file that gets downloaded or the URL to the resource you want to download.
    • a buffer (such as a bytes object): if the size of the buffer is smaller than the data_url_max_size configuration setting, then the python-magic package is used to determine the MIME type of the buffer content, and the download is performed using a generated "data:" URL with the relevant type, and a base64-encoded version of the buffer content.
      If the buffer is too large, its content is transferred after saving it in a temporary server file.
  • on_action: this callback is triggered when the transfer of the content is achieved.
    In this function, you can perform any clean-up operation that could be required after the download is completed.
    This callback can use three optional parameters:
    • state: the State instance of the caller.
    • id (optional): a string representing the identifier of the caller. If this function is called directly, this will always be "Gui.download". Some controls may also trigger download actions, and then id would reflect the identifier of those controls.
    • payload (optional): an optional payload from the caller.
      This is a dictionary with the following keys:
      • action: the name of the callback;
      • args: an array of two strings. The first element reflects the name parameter, and the second element reflects the server-side URL where the file is located.