Skip to content

Commit

Permalink
fix: gdocs-docx upload
Browse files Browse the repository at this point in the history
  • Loading branch information
milovate committed Dec 14, 2024
1 parent 9909115 commit 855adce
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion daras_ai_v2/gdrive_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def download_blob_file_content(
_, done = downloader.next_chunk()
# print(f"Download {int(status.progress() * 100)}%")
except HttpError as error:
# retry if error exporting google docs format files e.g .pptx files uploaded to docs.google.com
# retry if error exporting google docs format files e.g .pptx/.docx files uploaded to docs.google.com
if "presentation" in f.path.segments:
# update mime_type to download the file directly
mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
Expand All @@ -123,6 +123,19 @@ def download_blob_file_content(
while done is False:
_, done = downloader.next_chunk()

elif "document" in f.path.segments:
mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
request, _ = service_request(
service, file_id, f, mime_type, retried_request=True
)
downloader = MediaIoBaseDownload(file, request)
done = False
while done is False:
_, done = downloader.next_chunk()

else:
raise error

f_bytes = file.getvalue()
return f_bytes, mime_type

Expand Down

0 comments on commit 855adce

Please sign in to comment.