Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion drive_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload

_SCOPES = ["https://www.googleapis.com/auth/drive.file"]
_SCOPES = ["https://www.googleapis.com/auth/drive"]


def _get_service():
Expand All @@ -58,6 +58,23 @@ def _get_service():
return build("drive", "v3", credentials=creds)


def _check_folder(service, folder_id: str) -> None:
"""Verify the Drive folder is accessible; raise a clear error if not."""
from googleapiclient.errors import HttpError # lazy — avoids top-level import failure in envs without the package

try:
service.files().get(fileId=folder_id, fields="id").execute()
except HttpError as exc:
if exc.resp.status == 404:
raise RuntimeError(
f"Google Drive folder '{folder_id}' was not found or is not "
"accessible by the service account. "
"Share the folder with the service account email address "
"(Editor access) and try again."
) from exc
raise


def upload_logs(folder_id: str, *file_paths: str, date_suffix: str = None) -> list:
"""
Upload one or more files to a Google Drive folder.
Expand All @@ -81,6 +98,7 @@ def upload_logs(folder_id: str, *file_paths: str, date_suffix: str = None) -> li
list of dicts with keys 'name' and 'url' for each uploaded file.
"""
service = _get_service()
_check_folder(service, folder_id)
results = []

for path in file_paths:
Expand Down