Skip to main content

Upload

The Data Upload widget allows you to upload files from your local system to your notebook environment, offering the feature as a customizable button.

Widget Data Upload

Basic usage

First, create a Data Upload widget and configure the necessary settings. For example, you can set the output variable to store the file path of the uploaded file.

Configuration

To configure the widget, you need to either set the destination folder or bind a Python variable that contains a string with the project path.

In the context of Python, after uploading a file, the user will have access to automatically injected variables related to the uploaded files:

  • $out: Contains a dictionary with filepath and filename properties.
  • $out_fullpath: Contains a string with the full absolute path of the uploaded file(s).
  • $out_project_path: Contains the path of the uploaded files, starting from the project root.

These variables can be used, for instance, in an image widget for previewing if an image file was uploaded. Here is an example of how you can use these in a Python script:

# Assuming your output variable name is `uploaded_file`

# Use the fullpath for opening the file in Python
with open(uploaded_file_fullpath, 'rb') as file:
# Process the file
pass

# Use the project path to display or use the file in other widgets
image_widget_path = uploaded_file_project_path

File type options

You can specify the types of files that are allowed for upload using the Accept setting. The options are:

  • image/*: Images
  • video/*: Videos
  • audio/*: Audio files
  • .pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt: Documents
  • .xls,.xlsx,.csv: Spreadsheets
  • .txt: Text files
  • .zip,.rar,.7z: Compressed files
  • */*: Any filetype

API reference

Basic

Setting nameTypeDescriptionDefault
Output variablestring/variable_nameName of the variable to store the file path
File pathstring/filesystem_pathPath where the file will be stored./myfile
MandatorybooleanIf true, execution stops until a file is uploadedfalse
AcceptstringAccepted file types*/*
Modedefault | smallSize of the upload buttondefault
TitlestringTitle to display above the upload button
SubtitlestringSubtitle to display above the upload button

Style

Container

Setting nameTypeDescriptionDefault
Container paddingstring/css_paddingPadding of the container.

Alignment

Setting nameTypeDescriptionDefault
Vertical alignmentstart | center | endVertical alignment of the containercenter
Horizontal alignmentleft | center | rightHorizontal alignment of the containercenter

See also

  • All widgets — browse the full widget catalog.
  • Download — the counterpart for letting users download files.
  • Image — preview uploaded image files.