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