File browser: upload progress bar (0.21.5)
filesApi.upload now accepts an onProgress callback wired to axios onUploadProgress; the Files page shows a progress bar with percentage while uploading. Single-file upload tracks that file's bytes; folder upload tracks overall progress across the N files (file i/N + current file's bytes). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
8fc61b1531
commit
cf046648bd
@@ -63,13 +63,27 @@ export const filesApi = {
|
||||
triggerDownload(res.data as Blob, filename);
|
||||
},
|
||||
|
||||
upload: async (path: string, file: File, overwrite = false, relPath = "", agentId?: number) => {
|
||||
upload: async (
|
||||
path: string,
|
||||
file: File,
|
||||
overwrite = false,
|
||||
relPath = "",
|
||||
agentId?: number,
|
||||
onProgress?: (pct: number) => void,
|
||||
) => {
|
||||
const form = new FormData();
|
||||
form.append("path", path);
|
||||
form.append("overwrite", String(overwrite));
|
||||
if (relPath) form.append("rel_path", relPath);
|
||||
form.append("file", file);
|
||||
const res = await api.post<{ ok: boolean; name: string }>(`${base(agentId)}/upload`, form);
|
||||
const res = await api.post<{ ok: boolean; name: string }>(`${base(agentId)}/upload`, form, {
|
||||
onUploadProgress: onProgress
|
||||
? (e) => {
|
||||
const pct = e.total ? (e.loaded / e.total) * 100 : (e.progress ?? 0) * 100;
|
||||
onProgress(Math.min(pct, 100));
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
return res.data;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user