MediaIoBaseDownload Cannot Handle Resuming Partial Download · Issue #2309 · googleapis/google-api-python-client · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

MediaIoBaseDownload Cannot Handle Resuming Partial Download #2309

Closed
@coanghel

Description

@coanghel

Title summarizes the issue. As is, you cannot resume a partial download by using MediaIoBaseDownload()

Steps to reproduce

  1. Start a download with MediaIoBaseDownload() and interrupt it
  2. Create a new request and pass the relevant Range header to resume the download
  3. Starting a new download with the above request will always start the download from byte 0 due to the constructor for MediaIoBaseDownload() setting progress to 0, and the range header being overwritten in next_chunk()

Code example

try:
        headers = {'Range': f'bytes={partial_size}-'} if partial_size > 0 and partial_size < total_size else {}
        request = thread_service.files().get_media(fileId=file_id)
        request.headers.update(headers)

        with open(local_file_path, 'ab' if partial_size > 0 else 'wb') as f:
            downloader = MediaIoBaseDownload(f, request, chunksize=1024*1024*15)
            done = False
            while not done:
                _, done = downloader.next_chunk()
    except HttpError as error:
        print(f"An error occurred while downloading {file_name}: {error}")
        return False

Metadata

Metadata

Assignees

Labels

status: investigatingThe issue is under investigation, which is determined to be non-trivial.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    TMZ Celebrity News – Breaking Stories, Videos & Gossip

    Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

    Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

    🎥 Watch TMZ Live

    TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.