lib/file-upload
File uploads, shared by both transports.
Every upload is HTTP POSTs to /api/upload rather than a stream of chunks
over the WebSocket or a data channel: the browser's native HTTP path and
the server's C-accelerated aiohttp saturate the link, whereas per-message
chunk processing is bounded by pure-Python per-chunk work, and an upload
cannot stall or kill the realtime session socket. The destination path
rides URL-encoded in the X-Upload-Path header, the secure-mode session
token as a Bearer header, and progress is reported to the dashboards as
{type: 'fileUpload'} window messages with the statuses start,
progress, end, error and warning.
Files at or under UPLOAD_CHUNK_BYTES go up as one plain POST (the whole
Blob, no extra headers, the shape every server accepts). Larger files are
sliced with Blob.slice, never read into memory, into sequential POSTs of
at most UPLOAD_CHUNK_BYTES so no single request body exceeds a fronting
proxy's per-request cap (Cloudflare rejects bodies over 100 MB). Each slice
carries the same X-Upload-Path plus X-Upload-Id (an opaque per-file
transfer id), X-Upload-Offset (the slice's absolute byte offset),
X-Upload-Total (the final file size in bytes) and, on the last slice,
X-Upload-Final: 1. The server appends slices to a .part file and
atomically renames it into place on the final one. Progress is cumulative
across slices, so the dashboards render one smooth bar per file.
One upload operation (a file-picker set or a dropped tree) runs at a time: sequential POSTs keep server-side writes ordered and the progress UI coherent.
Interfaces
FileUploader
Defined in: lib/file-upload.js:42
Properties
uploadFileObject
uploadFileObject: (file, pathToSend) => Promise<void>;Defined in: lib/file-upload.js:43
Uploads one file to the given destination path, reporting progress.
Parameters
| Parameter | Type |
|---|---|
file | File |
pathToSend | string |
Returns
Promise<void>
handleRequestFileUpload
handleRequestFileUpload: () => void;Defined in: lib/file-upload.js:45
Opens the hidden file picker.
Returns
void
handleFileInputChange
handleFileInputChange: (event) => Promise<void>;Defined in: lib/file-upload.js:46
Uploads the picker's files sequentially.
Parameters
| Parameter | Type |
|---|---|
event | Event |
Returns
Promise<void>
handleDragOver
handleDragOver: (ev) => void;Defined in: lib/file-upload.js:48
Sets the drop effect.
Parameters
| Parameter | Type |
|---|---|
ev | DragEvent |
Returns
void
handleDrop
handleDrop: (ev) => Promise<void>;Defined in: lib/file-upload.js:49
Uploads dropped files and directory trees sequentially.
Parameters
| Parameter | Type |
|---|---|
ev | DragEvent |
Returns
Promise<void>
Functions
createFileUploader()
function createFileUploader(options?): FileUploader;Defined in: lib/file-upload.js:60
Creates the upload handlers a core wires to its page.
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | { canUpload?: () => boolean; } | - |
options.canUpload? | () => boolean | Per-core gate; a shared or viewer session returns false and every entry point refuses. |
Returns
postUploadBody()
function postUploadBody(
url,
pathToSend,
body,
extraHeaders,
onProgress
): Promise<void>;Defined in: lib/file-upload.js:88
One POST of a File or Blob slice. Resolves on 2xx and rejects with the
dashboard-facing message otherwise; upload progress is relayed to
onProgress raw so the caller can accumulate across slices.
Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | The upload endpoint. |
pathToSend | string | Destination path. |
body | Blob | The bytes. |
extraHeaders | any | Slice headers, if any. |
onProgress | (e) => void | Upload progress listener. |
Returns
Promise<void>
uploadFileObject()
function uploadFileObject(file, pathToSend): Promise<void>;Defined in: lib/file-upload.js:120
Uploads one file, as a single POST or as slices by size, reporting
start, cumulative progress and end or error.
Parameters
| Parameter | Type | Description |
|---|---|---|
file | File | The file. |
pathToSend | string | Destination path. |
Returns
Promise<void>
Throws
The upload failure, after reporting it.
handleDroppedEntry()
function handleDroppedEntry(entry, basePathFallback?): Promise<void>;Defined in: lib/file-upload.js:175
Uploads a dropped file or, recursively, a dropped directory. The
entry's fullPath preserves a dropped directory's internal structure;
the fallback rebuilds it from the recursion for browsers without one.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
entry | FileSystemEntry | undefined | The dropped entry. |
basePathFallback? | string | "" | Parent path when fullPath is absent. |
Returns
Promise<void>