Skip to content

file_download

Allows downloading of a file content.

Image format

Note that if the content is provided as a buffer of bytes, it can be converted to an image content if and only if you have installed the python-magic Python package (as well as python-magic-bin if your platform is Windows).

The download can be triggered when clicking on a button, or can be performed automatically.

Properties

Name Type Default Description
content(★) dynamic(url | path | file | ReadableBuffer)

The content of the file.

If a buffer is provided (string, array of bytes...), and in order to prevent the bandwidth to be consumed too much, the way the data is transferred depends on the the data_url_max_size parameter of the application configuration (which is set to 50kB by default):

  • If the size of the buffer 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 size of the buffer is greater than this setting, then it is transferred through a temporary file.

label dynamic(str)

The label of the button.

on_action Callback

The name of a function that is triggered when the download is initiated. All the parameters of that function are optional:

  • state (State): the state instance.
  • id (optional[str]): the identifier of the button.
  • action (optional[str]): the name of the action that provoked the change.

auto bool False

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

render dynamic(bool) True

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

bypass_preview bool True

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

name str

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

active dynamic(bool) True

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

id str

The identifier that will be assigned to the rendered HTML component.

properties dict[str, any]

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

class_name str

List of CSS class names that will be associated with the generated HTML Element. This class names will be added to the default taipy-<element_type>.

hover_text dynamic(str)

Information that is displayed when the user hovers over this element.

(★)content is the default property for this visual element.

Usage

Default behavior

Allows downloading content when content is a file path or some content.

Page content

<|{content}|file_download|>
<taipy:file_download>{content}</taipy:file_download>

Standard configuration

A specific label can be shown beside the standard icon.

The function name provided as on_action is called when the user initiates the download.

The name provided will be the default name proposed to the user when downloading (depending on browser validation and rules).

Page content

<|{content}|file_download|label=Download File|on_action=function_name|name=filename|>
<taipy:file_download on_action="function_name"  name="filename">{content}</taipy:file_download>

Preview file in the browser

The file content can be visualized in the browser (if supported and in another tab) by setting bypass_preview to False.

Page content

<|{content}|file_download|bypass_preview=False|>
<taipy:file_download bypass_preview="False">{content}</taipy:file_download>

Automatic download

The file content can be downloaded automatically (when the page shows and when the content is set).

Page content

<|{content}|file_download|auto|>
<taipy:file_download auto="True">{content}</taipy:file_download>