Add chunked upload for large files

This commit is contained in:
sarah committed 2026-09-28 23:16:11 +02:00
1 parent da4e02472f
commit 24a6d83ea0
5 files changed
+212 -19

No files matched your search

+45
View File
@@ -36,9 +36,11 @@ from Explorer import (
CreateEntry,
DeleteEntry,
EnsureDirectoryNote,
FinishChunkedUpload,
ListDirectory,
ListRoots,
MoveEntry,
SaveUploadChunk,
SaveUploadedFile,
)
from Groups import (
@@ -465,6 +467,49 @@ async def PostUploadEndpoint(
return {"Saved": SavedNames, "Errors": Errors}
@Application.post("/api/upload/chunk")
async def PostUploadChunkEndpoint(
Root: str,
Path: str,
UploadId: str,
ChunkIndex: int,
TotalChunks: int,
FileName: str,
Chunk: UploadFile = File(...),
CurrentUser: dict = Depends(GetCurrentUser),
) -> dict:
RequirePathAccessible(Root, Path, CurrentUser)
try:
ChunkBytes = await Chunk.read()
SaveUploadChunk(UploadId, ChunkIndex, ChunkBytes)
except ValueError as Error:
raise HTTPException(status_code=400, detail=str(Error))
return {"Received": ChunkIndex}
@Application.post("/api/upload/complete")
def PostUploadCompleteEndpoint(
Root: str,
Path: str,
UploadId: str,
TotalChunks: int,
FileName: str,
CurrentUser: dict = Depends(GetCurrentUser),
) -> dict:
RequirePathAccessible(Root, Path, CurrentUser)
try:
SavedName = FinishChunkedUpload(Root, Path, UploadId, TotalChunks, FileName)
except (ValueError, FileExistsError, NotADirectoryError) as Error:
raise HTTPException(status_code=400, detail=str(Error))
except OSError as Error:
raise HTTPException(status_code=400, detail=f"Could not save file ({Error})")
return {"Saved": SavedName}
class MoveEntryRequest(BaseModel):
NewName: str | None = None
DestinationPath: str | None = None