Gemini.Types.File (GeminiEx v0.8.2)
View SourceType definitions for file management operations.
The Files API allows uploading, downloading, and managing files that can be used with Gemini models for multimodal content generation.
File States
Files go through several states during processing:
:state_unspecified- Initial/unknown state:processing- File is being processed:active- File is ready to use:failed- Processing failed
File Sources
:source_unspecified- Unknown source:uploaded- User uploaded the file:generated- API generated the file (e.g., from video generation)
Example
# Upload a file
{:ok, file} = Gemini.upload_file("path/to/image.png")
# Check file state
case file.state do
:active -> IO.puts("File is ready: #{file.uri}")
:processing -> IO.puts("Still processing...")
:failed -> IO.puts("Failed: #{file.error}")
end
# Use in content generation
{:ok, response} = Gemini.generate([
%{type: "text", text: "What's in this image?"},
%{type: "file", uri: file.uri, mime_type: file.mime_type}
])
Summary
Types
File source enumeration values.
File state enumeration values.
File status/error information.
Represents a file in the Gemini API.
Video metadata for video files.
Functions
Checks if the file is ready to use.
Checks if the file can be downloaded (only generated files).
Checks if the file processing failed.
Creates a new File struct from API response.
Extracts the file ID from the file name.
Parses API source string to atom.
Parses API state string to atom.
Checks if the file is still processing.
Converts file source atom to API string format.
Converts file state atom to API string format.
Types
@type file_source() :: :source_unspecified | :uploaded | :generated
File source enumeration values.
:source_unspecified- Unknown source:uploaded- User uploaded the file:generated- API generated the file (e.g., video generation)
@type file_state() :: :state_unspecified | :processing | :active | :failed
File state enumeration values.
:state_unspecified- Initial/unknown state:processing- File is being processed by the API:active- File is ready to use in requests:failed- File processing failed (check error field)
File status/error information.
@type t() :: %Gemini.Types.File{ create_time: String.t() | nil, display_name: String.t() | nil, download_uri: String.t() | nil, error: file_status() | nil, expiration_time: String.t() | nil, mime_type: String.t() | nil, name: String.t() | nil, sha256_hash: String.t() | nil, size_bytes: integer() | nil, source: file_source() | nil, state: file_state() | nil, update_time: String.t() | nil, uri: String.t() | nil, video_metadata: video_metadata() | nil }
Represents a file in the Gemini API.
Writable Fields (can be set on upload)
name- Resource name (format: "files/{file_id}")display_name- Human-readable display name (max 512 characters)mime_type- MIME type (e.g., "image/png", "video/mp4")
Read-Only Fields (output only)
size_bytes- File size in bytescreate_time- Creation timestamp (ISO 8601)expiration_time- When the file expires (ISO 8601)update_time- Last update timestamp (ISO 8601)sha256_hash- Base64-encoded SHA256 hashuri- URI for using the file in content (e.g., "gs://...")download_uri- Download URI (only for generated files)state- Current processing statesource- How the file was createdvideo_metadata- Metadata for video fileserror- Error information if state is :failed
@type video_metadata() :: %{ optional(:video_duration) => String.t(), optional(:video_duration_seconds) => integer() }
Video metadata for video files.
Functions
Checks if the file is ready to use.
Checks if the file can be downloaded (only generated files).
Checks if the file processing failed.
Creates a new File struct from API response.
Parameters
response- Map from API response with string keys
Examples
response = %{
"name" => "files/abc123",
"displayName" => "my-image.png",
"mimeType" => "image/png",
"sizeBytes" => "1024",
"state" => "ACTIVE"
}
file = Gemini.Types.File.from_api_response(response)
Extracts the file ID from the file name.
Examples
file = %Gemini.Types.File{name: "files/abc123"}
Gemini.Types.File.get_id(file)
# => "abc123"
@spec parse_source(String.t() | nil) :: file_source() | nil
Parses API source string to atom.
@spec parse_state(String.t() | nil) :: file_state() | nil
Parses API state string to atom.
Checks if the file is still processing.
@spec source_to_api(file_source()) :: String.t()
Converts file source atom to API string format.
@spec state_to_api(file_state()) :: String.t()
Converts file state atom to API string format.