feat(synology): implement chunked upload for large videos#1488
Merged
mengyushen merged 3 commits intoApr 2, 2026
Conversation
## Goal
The goal of this change is to provide a more robust upload mechanism for large video files in `SynologyDTPService`. By switching from a single-stream upload to a chunked upload process, we improve reliability for very large transfers and align with the Synology C2 API's preferred method for handling significant media payloads.
## Changes
- **Chunked Upload Logic:** Refactored `createVideo` to use a multi-step upload process:
- `uploadVideoChunks`: Reads the video stream in 50MB increments and uploads each chunk sequentially to the new `/import/item/chunk` endpoint.
- `completeVideoUpload`: Sends a final request to `/import/item/complete` with the total chunk count and metadata (title, description, timestamp) to finalize the file.
- **API Configuration:**
- Updated `C2Api` and `synology.yaml` to include paths for the new chunk and completion endpoints.
- **Client Optimization:**
- Updated `configureClient` to force **HTTP/1.1** and increased the default read timeout to 120 seconds to ensure stable long-running connections during chunk transmission.
- Simplified `sendPostRequest` by removing the manual timeout override, relying instead on the pre-configured client.
- **Memory Efficiency:** Reuses a single byte array buffer for chunking to minimize heap allocations during the transfer of large files.
## Testing
- **OOM Validation:** Updated `SynologyDTPServiceOOMTest` to verify that a 1GB video is correctly split into multiple chunks and uploaded without exceeding memory limits.
- **Functional Tests:** Updated `SynologyDTPServiceTest` to accommodate the new two-step upload flow (Multipart chunks followed by a FormBody completion) and added a specific case `shouldSendMultipleChunksForLargeVideo` to verify correct indexing.
04fdd06 to
4faa5de
Compare
yukthagaduputi
approved these changes
Apr 2, 2026
mengyushen
approved these changes
Apr 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
The goal of this change is to provide a more robust upload mechanism for large video files in
SynologyDTPService. By switching from a single-stream upload to a chunked upload process, we improve reliability for very large transfers and align with the Synology C2 API's preferred method for handling significant media payloads.Changes
createVideoto use a multi-step upload process:uploadVideoChunks: Reads the video stream in 50MB increments and uploads each chunk sequentially to the new/import/item/chunkendpoint.completeVideoUpload: Sends a final request to/import/item/completewith the total chunk count and metadata (title, description, timestamp) to finalize the file.C2Apiandsynology.yamlto include paths for the new chunk and completion endpoints.configureClientto force HTTP/1.1 and increased the default read timeout to 120 seconds to ensure stable long-running connections during chunk transmission.sendPostRequestby removing the manual timeout override, relying instead on the pre-configured client.Testing
SynologyDTPServiceOOMTestto verify that a 1GB video is correctly split into multiple chunks and uploaded without exceeding memory limits.SynologyDTPServiceTestto accommodate the new two-step upload flow (Multipart chunks followed by a FormBody completion) and added a specific caseshouldSendMultipleChunksForLargeVideoto verify correct indexing.