File Input - Writer AI Studio

Fields

Name Type Description Options
Label Text - -
Allowed file types Text Provides hints for browsers to select the correct file types. You can specify extensions and MIME types separated by comma, or leave empty to accept any file. -
Allow multiple files Boolean - -
Custom CSS classes Text CSS classes, separated by spaces. You can define classes in custom stylesheets. -

Events

wf-file-change
Capture changes to this control.

def onchange_handler(state, payload):

# An array of dictionaries is provided in the payload
    # The dictionaries have the properties name, type and data
    # The data property is a file-like object

uploaded_files = payload
    for i, uploaded_file in enumerate(uploaded_files):
        name = uploaded_file.get("name")
        file_data = uploaded_file.get("data")
        with open(f"{name}-{i}.jpeg", "wb") as file_handle:
            file_handle.write(file_data)