pl-file-download element¶
Provide a download link to a static or dynamically generated file.
Sample element¶

question.html
<!-- allow students to download an existing file -->
<pl-file-download file-name="data.txt" directory="clientFilesCourse"></pl-file-download>
<!-- allow students to download a file that is generated by code -->
<pl-file-download file-name="data.txt" type="dynamic"></pl-file-download>
<!-- allow students to open an existing file in a new tab -->
<pl-file-download
file-name="data.txt"
directory="clientFilesCourse"
force-download="false"
></pl-file-download>
Customizations¶
| Attribute | Type | Default | Description |
|---|---|---|---|
directory |
string | "clientFilesQuestion" |
The directory that contains the file, either "clientFilesQuestion" or clientFilesCourse (see client and server files). A directory cannot be specified if type="dynamic". |
file-name |
string | — | Name of file to download. |
force-download |
boolean | true | Force a file download. Otherwise, allow the browser to open the file in a new tab. |
label |
string | See description | Displayed label on the download link. Defaults to the name of the file specified in file-name. Can contain HTML if explicitly set, though the code must be properly escaped (e.g., for a label of <strong>Download</strong> File use label="<strong>Download</strong> File"). |
type |
"static" or "dynamic" |
"static" |
Type of file, either "static" (an existing file) or "dynamic" (a file generated by element or server code). |
Details¶
If type="dynamic", then the contents of the file must be returned by a function file() that is located either in element code or in server.py. The contents must be a string (with utf-8 encoding), a bytes-like object, or a file-like object. The filename will be available to this function as data["filename"]. For example, this code might appear in server.py to generate a file called data.txt:
server.py
def file(data):
if data["filename"] == "data.txt":
return "This data is generated by code."
If file() does not return anything, it will be treated as if file() returned the empty string.