fix: Empty last chunk case in resumable upload that is not a stream#1802
fix: Empty last chunk case in resumable upload that is not a stream#1802john0312 wants to merge 1 commit intogoogleapis:mainfrom
Conversation
|
For an upload that inherits the MediaUpload class and is not a stream, if the size of the upload is exact multiples of the chunksize, the last chunk would be empty and the generated Content-Range header will result in "Bad Request". Details: "Failed to parse Content-Range header."
1f7f160 to
328bea8
Compare
vchudnov-g
left a comment
There was a problem hiding this comment.
PTAL at my suggestion for clarity/code-deduping.
Otherwise, LGTM
| # sending "bytes 0--1/0" results in an invalid request | ||
| # Only add header "Content-Range" if chunk_end != -1 | ||
| if chunk_end != -1: | ||
| if chunk_end - self.resumable_progress + 1 == 0 and chunk_end != -1: |
There was a problem hiding this comment.
I suggest assigning
content_length = chunk_end - self.resumable_progress + 1 == 0 and chunk_end
before the headers = ... line and using content_length both for the header and in this conditional.
There was a problem hiding this comment.
I am not sure I am tracking here on two things.
One: Do you mean for this to equate to a boolean?
This line from your example:
chunk_end - self.resumable_progress + 1 == 0 and chunk_end
yields True or False.
And yet content_length feels like the name for an numerial value.
Two: Can you simply suggest the code edit you want to see using GitHub's suggestion tool?
I am not tracking exactly what you want in terms of placement and modifications of the new code. Are you suggesting the following? This seems like doesn't do what we want (especially if content_length is a boolean)?
| if chunk_end - self.resumable_progress + 1 == 0 and chunk_end != -1: | |
| content_length = chunk_end - self.resumable_progress + 1 == 0 and chunk_end != -1 | |
| if content_length: | |
| headers["Content-Range"] = "bytes */%s" % (content_length,) |
For an upload that inherits the MediaUpload class and is not a stream,
if the size of the upload is exact multiples of the chunksize, the last
chunk would be empty and the generated Content-Range header will result
in "Bad Request". Details: "Failed to parse Content-Range header."
Fixes #1801 🦕