Skip to content

Conversation

@WaveringAna
Copy link
Owner

This commit introduces chunked file uploading for large files, improving the reliability and user experience for uploads.

Key changes:

  • Server-side (app/routes/index.ts):

    • Added POST /upload/chunk endpoint to receive individual file chunks and store them temporarily in uploads/tmp/<originalFilename>/<chunkIndex>.
    • Added POST /upload/complete endpoint to verify all chunks, assemble them into the final file in uploads/, and then integrate with existing media processing (database update, transcoding via MediaProcesser).
    • Enhanced error handling for chunk upload and assembly processes.
    • Multer configured for chunk handling.
  • Client-side (app/public/js/index.js):

    • Updated FileUploader class to slice large files (configurable threshold, e.g., >20MB) into smaller chunks (e.g., 5MB).
    • Chunks are uploaded sequentially to /upload/chunk.
    • After all chunks are sent, a request is made to /upload/complete.
    • Progress indication is provided to you during chunked uploads.
    • Error handling and retry mechanism for chunk uploads.
  • Error Handling & Cleanup (app/lib/cleanup.ts):

    • Added cleanupOrphanedChunks utility function to scan uploads/tmp/ and remove old, incomplete chunk directories, preventing disk space issues. This function can be triggered by a scheduled job.
  • Testing (tests/chunkedUpload.test.ts):

    • Added a new test suite for the chunked upload functionality.
    • Tests cover successful end-to-end uploads, handling of missing chunks, invalid metadata, and authentication for protected routes.

This feature addresses issue #6 (chunk uploading for large files).

This commit introduces chunked file uploading for large files, improving the reliability and user experience for uploads.

Key changes:

-   **Server-side (app/routes/index.ts):**
    -   Added `POST /upload/chunk` endpoint to receive individual file chunks and store them temporarily in `uploads/tmp/<originalFilename>/<chunkIndex>`.
    -   Added `POST /upload/complete` endpoint to verify all chunks, assemble them into the final file in `uploads/`, and then integrate with existing media processing (database update, transcoding via `MediaProcesser`).
    -   Enhanced error handling for chunk upload and assembly processes.
    -   Multer configured for chunk handling.

-   **Client-side (app/public/js/index.js):**
    -   Updated `FileUploader` class to slice large files (configurable threshold, e.g., >20MB) into smaller chunks (e.g., 5MB).
    -   Chunks are uploaded sequentially to `/upload/chunk`.
    -   After all chunks are sent, a request is made to `/upload/complete`.
    -   Progress indication is provided to you during chunked uploads.
    -   Error handling and retry mechanism for chunk uploads.

-   **Error Handling & Cleanup (app/lib/cleanup.ts):**
    -   Added `cleanupOrphanedChunks` utility function to scan `uploads/tmp/` and remove old, incomplete chunk directories, preventing disk space issues. This function can be triggered by a scheduled job.

-   **Testing (tests/chunkedUpload.test.ts):**
    -   Added a new test suite for the chunked upload functionality.
    -   Tests cover successful end-to-end uploads, handling of missing chunks, invalid metadata, and authentication for protected routes.

This feature addresses issue #6 (chunk uploading for large files).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants