Repository navigation
fix: correct Content-Range end byte in chunked upload (RFC 7233) - #212
chrisdebian wants to merge 2 commits into
Conversation
Hard-coded 4096x1344 values only work for one specific GoPro MAX recording mode. Use exiftool computed-value syntax so CroppedArea and FullPano tags are derived from actual ImageWidth/ImageHeight, making the command work for any output resolution (e.g. 4096x2048). CroppedAreaTopPixels = (ImageWidth/2 - ImageHeight) / 2 Closes mapilio#200
The upload loop was sending `bytes={offset}-{entity_size}/{entity_size}`
for every chunk. RFC 7233 requires the end value to be the last byte of
the *current chunk* (0-indexed, inclusive), not the total entity size.
For multi-chunk uploads this caused the server to reject intermediate
chunks with "Invalid Content-Range provided" (MapSyncer issue mapilio#87).
Fix: compute `chunk_end = offset + len(chunk) - 1` for non-empty chunks
and keep the existing sentinel value for the empty finalisation request.
Adds two unit tests covering single-chunk and multi-chunk Content-Range
header construction.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ozcan-durak
left a comment
There was a problem hiding this comment.
Thanks, Chris. I tested this against the repository image-server handler. The current client passes all six transfer cases; this patch fails the one-byte file, final remainder and resumed-final-byte cases. We need to align the client and server contract before merging. Please also separate the GoPro change underneath this commit.
| headers = { | ||
| 'Connection': "keep-alive", | ||
| "content-range": f"bytes={offset}-{self.entity_size}/{self.entity_size}", | ||
| "content-range": f"bytes={offset}-{chunk_end}/{self.entity_size}", |
There was a problem hiding this comment.
The server rejects rangeStart >= rangeEnd. For a 101-byte file with 100-byte chunks, this emits bytes=100-100/101 for the final byte and gets HTTP 400. A one-byte file and a resume with one byte remaining fail too. Please add actual transfer tests for these boundaries; the current equals-sign protocol has a separate completion request, so changing only the end offset is incompatible.
|
Thanks for testing this so thoroughly, Ozcan. You're right: I'd treated the header as the standard HTTP range format, but it's the upload server's own contract (the end value is the total size, and an empty final chunk completes the upload). The current client already matches it, so I'm closing this PR rather than changing both sides. The GoPro change is still in #211 on its own, so closing this one doesn't affect it. If it would help, I could open a small PR with tests for your six transfer cases (including the one-byte file, the final remainder and resuming with one byte left), plus a short comment in Chris |
|
Thanks, Chris. Yes, please send the six transfer cases as a test-only PR, with the short comment explaining the server's range format. Keeping that contract covered should help avoid the same confusion later. The GoPro change can stay separate in #211. |
Summary
Invalid "Content-Range" providederror when uploading large tracks (>64 MB, i.e. more than one chunk).upload_manager.pywas sendingbytes={offset}-{entity_size}/{entity_size}for every chunk. RFC 7233 requires the end value to be the last byte of the current chunk (0-indexed, inclusive), not the total file size. For multi-chunk uploads this meant every intermediate chunk carried an invalid range, causing the server to reject it.Root cause
Related issues
Test plan
pytest tests/test_upload_manager.py— 2 new tests passpytest— 97 tests passInvalid Content-Rangeerror🤖 Generated with Claude Code