Closed
Description
Title summarizes the issue. As is, you cannot resume a partial download by using MediaIoBaseDownload()
Steps to reproduce
- Start a download with
MediaIoBaseDownload()
and interrupt it - Create a new request and pass the relevant Range header to resume the download
- 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 innext_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