Skip to content

fix: Empty last chunk case in resumable upload that is not a stream#1802

Open
john0312 wants to merge 1 commit intogoogleapis:mainfrom
john0312:fix-empty-last-chunk
Open

fix: Empty last chunk case in resumable upload that is not a stream#1802
john0312 wants to merge 1 commit intogoogleapis:mainfrom
john0312:fix-empty-last-chunk

Conversation

@john0312
Copy link
Copy Markdown

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 🦕

@john0312 john0312 requested a review from a team as a code owner May 16, 2022 13:51
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label May 16, 2022
@parthea parthea self-assigned this May 17, 2022
@Blessed4eva
Copy link
Copy Markdown

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."

@parthea parthea removed their assignment Oct 25, 2024
@chalmerlowe chalmerlowe requested a review from a team as a code owner December 11, 2025 16:32
@chalmerlowe chalmerlowe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 11, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 11, 2025
Copy link
Copy Markdown

@chalmerlowe chalmerlowe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

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."
@john0312 john0312 force-pushed the fix-empty-last-chunk branch from 1f7f160 to 328bea8 Compare April 2, 2026 20:36
@john0312 john0312 requested a review from a team as a code owner April 2, 2026 20:36
Copy link
Copy Markdown
Contributor

@vchudnov-g vchudnov-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vchudnov-g

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)?

Suggested change
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,)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MediaUpload with has_stream() = False and an empty last chunk results in HTTP Error 400

7 participants