Uploads a file to the Gemini File API, making it available for use in generation requests with large files, videos, or audio.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/googleapis/python-genai/llms.txt
Use this file to discover all available pages before exploring further.
Method Signature
Parameters
The file to upload.Can be:
- A file path as a string:
"/path/to/file.pdf" - A PathLike object:
Path("document.pdf") - An IOBase object (file handle): Must be opened in binary mode (
'rb') and be seekable
Optional configuration for the upload.Available options:
display_name: Human-readable name for the filemime_type: MIME type (auto-detected if not provided)name: Custom resource namehttp_options: Custom HTTP request options
Returns
A File object containing:
name: The resource name (e.g.,"files/abc123")uri: The URI to reference in API callsdisplay_name: Human-readable namemime_type: The file’s MIME typesize_bytes: File size in bytescreate_time: When the file was uploadedupdate_time: Last update timeexpiration_time: When the file will be deletedstate: Upload state (PROCESSING,ACTIVE, orFAILED)
Examples
Upload PDF Document
Upload with Display Name
Upload Video File
Upload from File Handle
Upload and Use in Prompt
Upload Multiple Files
Async Upload
Upload with Custom MIME Type
Upload Audio File
File Lifecycle
Uploaded files are automatically deleted after 48 hours. Plan your workflows accordingly or re-upload files as needed.
Error Handling
API Availability
Related Methods
- files.get - Retrieve file metadata
- files.list - List uploaded files
- files.delete - Delete a file
- files.download - Download generated files