Class GeminiFiles
The Gemini models support multimodal inputs including text, images, audio, videos, and documents. Use this API to upload media files when the total request size exceeds 20 MB.
Files are stored for 48 hours and can be referenced in content generation requests using their URI. The API supports up to 20 GB of files per project, with a maximum of 2 GB per individual file. During the retention period, you can retrieve file metadata but cannot download the files directly.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic final recordRepresents a file uploaded to the Gemini API, documentation -
Method Summary
Modifier and TypeMethodDescriptionstatic GeminiFiles.Builderbuilder()voiddeleteFile(String name) Deletes an uploaded file by name.getMetadata(String name) Retrieves metadata for a specific uploaded file.Lists all uploaded files.uploadFile(byte[] fileBytes, String mimeType, String name) Uploads a file to Gemini using the resumable upload protocol.uploadFile(Path filePath, @Nullable String displayName) Uploads a file to Gemini using the resumable upload protocol.
-
Method Details
-
builder
-
uploadFile
public GeminiFiles.GeminiFile uploadFile(Path filePath, @Nullable String displayName) throws IOException, InterruptedException Uploads a file to Gemini using the resumable upload protocol.Note: The Files API lets you store up to 20 GB of files per project, with a per-file maximum size of 2 GB. Files are stored for 48 hours.
- Parameters:
filePath- path to the file to uploaddisplayName- optional display name for the file- Throws:
IOExceptionInterruptedException
-
uploadFile
public GeminiFiles.GeminiFile uploadFile(byte[] fileBytes, String mimeType, String name) throws InterruptedException Uploads a file to Gemini using the resumable upload protocol.Note: The Files API lets you store up to 20 GB of files per project, with a per-file maximum size of 2 GB. Files are stored for 48 hours.
- Parameters:
fileBytes- byte array that is the file to be uploadedmimeType- mimetype of the file that is being uploadedname- optional display name for the file- Throws:
InterruptedException
-
getMetadata
Retrieves metadata for a specific uploaded file.- Parameters:
name- the name of the file to retrieve metadata for (e.g., "files/abc123")- Throws:
IOExceptionInterruptedException
-
listFiles
Lists all uploaded files. Returns a list of uploaded files.Note: The Files API lets you store up to 20 GB of files per project, with a per-file maximum size of 2 GB. Files are stored for 48 hours.
- Throws:
IOExceptionInterruptedException
-
deleteFile
Deletes an uploaded file by name.- Parameters:
name- the name of the file to delete (e.g., "files/abc123")- Throws:
IOExceptionInterruptedException
-