Skip to content

File Transfer

oldmangan edited this page Oct 6, 2026 · 2 revisions

wapyt.filetransfer is not a widget: it is a set of functions for native file pickers and streaming transfers. Bytes never cross into Python. A download is piped from the network straight into a file handle, and an upload goes from a File to XMLHttpRequest. Python decides what to transfer and shows progress.

from wapyt import filetransfer

async def on_download_click(_event):
    chosen = await filetransfer.pick_save_file("app.log")   # FIRST, while the click still counts
    if not chosen.ok:
        return                                               # cancelled is not an error
    result = await filetransfer.save_file(chosen.id, "/files/7/download?path=app.log",
                                          on_progress=lambda seen, total: show(seen, total))
    filetransfer.release(chosen.id)

Call the picker first

Every picker needs transient user activation, and the first await consumes it. Call pick_save_file, pick_folder or pick_files as the very first thing in the click handler, before any BFF call, or the browser raises SecurityError.

Browser support

The pickers are Chromium-only. Check capabilities().pickers and tell the user when they're missing, rather than silently falling back to download_via_anchor(), which saves to the downloads folder with no progress.

Functions

Function
capabilities() Capabilities(save_file, directory, open_file, secure_context); .pickers
pick_save_file(name) · pick_folder() · pick_files(multiple, directory) → TransferResult
save_file(handle_id, url, transfer_id, on_progress) Stream a URL into a picked file
save_into(folder_id, relative_path, url, ...) Into a picked folder, creating subfolders
exists(folder_id, name) Check before save_into overwrites
upload(url, file_id, fields, transfer_id, on_progress) Multipart POST with progress; pyTincture's CSRF token is attached, including under a custom cookie_namespace
adopt(file) Register a dropped File (see DataTable on_drop) for upload
resume(transfer_id) Continue a download that lost its connection (Range + If-Range)
cancel(transfer_id) · release(handle_id) · release_all() Control and cleanup
download_via_anchor(url, name) Fallback without pickers

TransferResult(ok, cancelled, error, id, name, bytes, via_anchor, files, resumable, retries, restarted): files holds PickedFile(id, name, size, path) for uploads, where path is folder-relative after a directory pick.

Clone this wiki locally