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 q.site.download(link, '.')
# 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(ui.link(label=f'{os.path.basename(link)} ({size} bytes)', download=True, path=link))
# Clean up
items.append(ui.button(name='back', label='Back', primary=True))
q.page['example'].items = items
q.page['example'] = ui.form_card(box='1 1 4 10', items=[
ui.text_xl('Upload some files'),
ui.file_upload(name='user_files', label='Upload', multiple=True),
await q.page.save()

Tags: โ€‚download โ€‚upload