Skip to main content

Uploads / Download

Accept files from the user and downloads them locally.

import os
import os.path
from h2o_wave import main, app, Q, ui

async def serve(q: Q):
links = q.args.user_files
if links:
items = [ui.text_xl('Files uploaded!')]
for link in links:
local_path = await, '.')
# The file is now available locally; process the file.
# To keep this example simple, we just read the file size.
size = os.path.getsize(local_path)

items.append('{os.path.basename(link)} ({size} bytes)', download=True, path=link))
# Clean up

items.append(ui.button(name='back', label='Back', primary=True))['example'].items = items
else:['example'] = ui.form_card(box='1 1 4 7', items=[
ui.text_xl('Upload some files'),
ui.file_upload(name='user_files', label='Upload', multiple=True),

Tags:  downloadupload