Skip to content

fix(files): wait for File API uploads to reach ACTIVE state before generation#2191

Open
Adewale-1 wants to merge 2 commits intogoogleapis:mainfrom
Adewale-1:fix/864-video-file-api
Open

fix(files): wait for File API uploads to reach ACTIVE state before generation#2191
Adewale-1 wants to merge 2 commits intogoogleapis:mainfrom
Adewale-1:fix/864-video-file-api

Conversation

@Adewale-1
Copy link

Problem

When a file is uploaded via the File API and immediately used in a generate_content request, the file may still be in PROCESSING state, causing the API to reject the request. This was the root cause of #864 where video understanding failed for File API uploads but worked for YouTube URLs.

Solution

  • Added _ensure_file_active() which polls the file state until ACTIVE (with configurable retries and delay)
  • Added _process_contents_for_generation() which applies this check to all File objects in the content before each generate_content call
  • Added FileProcessingError to errors.py for clear error messaging when a file fails to become ACTIVE

Both sync and async _generate_content / _generate_content_stream methods are covered.

Testing

Added test_file_state_handling.py with unit tests covering:

  • File in PROCESSING state that transitions to ACTIVE
  • File that transitions to FAILED
  • File that exceeds max retries
  • Already ACTIVE files (no polling)

Fixes #864

…neration

When a file is uploaded via the File API and immediately used in a
generate_content request, the file may still be in PROCESSING state,
causing the API to reject the request. This was the root cause of googleapis#864
where video understanding failed for File API uploads but worked for
YouTube URLs.

Add _ensure_file_active() which polls the file state until ACTIVE,
and _process_contents_for_generation() which applies this check to all
File objects in the content before each generate_content call.
Also add FileProcessingError for clear error messaging when a file
fails to become ACTIVE.

Fixes googleapis#864
Tests were mocking api_client.call_api but implementation uses
api_client.request with response.body as a JSON string.
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.

Video Understanding is not working for video uploaded through File API, while the same youtube video link works.

1 participant