Skip to content

feat: google drive internal formats support #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Apr 11, 2025

Conversation

mateuszkuprowski
Copy link
Contributor

This implementation replaces the older approach using the Google Drive API's
`files.export()` and `files.get_media()` methods, which were limited by export size
restrictions (~10MB hard cap for Google-native files).

**New mechanism:**
- Authenticates using a service account and generates a bearer token via `google-auth`.
- Uses `files().get(fileId=..., fields="exportLinks,webContentLink")` to fetch download URLs:
    - `exportLinks` is a dictionary of export MIME types (e.g., docx, pdf, pptx) for
      Google-native files like Docs, Sheets, and Slides.
    - `webContentLink` is a pre-authenticated direct download link for non-Google-native
      files (e.g., PDFs, images, ZIPs, etc.).
      
These links emulate the behavior of Google Drive's "File > Download as..." options
in the UI and bypass the size limitations of `files.export()`.

 **Behavior:**
- Google-native formats are downloaded using `exportLinks` in appropriate MIME formats.
- Binary files (non-Google-native) are downloaded using `webContentLink`.
- All downloads are performed via `requests.get()` using a valid bearer token.

Copy link

@pawel-kmiecik pawel-kmiecik left a comment

Choose a reason for hiding this comment

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

LGTM!

@bryan-unstructured
Copy link
Contributor

bryan-unstructured commented Apr 10, 2025

well, this is not related to your PR, but I find a previously existing bug :-) Can you please also update it?
between Line 444 - 447

def extract_permissions(self, permissions: Optional[list[dict]]) -> list[dict]:
        if not permissions:
            logger.debug("no permissions found")
            return {}

should return [{}], otherwise would cause error in some cases.
Overall the PR looks good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants