Uploads files to Google Gemini's File API.
Google uses a two-step resumable upload protocol internally, but this is
abstracted away — callers simply call upload/3.
Usage
{:ok, uploader} = LangChain.FileUploader.FileGoogle.new(%{api_key: "AI..."})
{:ok, result} = LangChain.FileUploader.upload(uploader, file_bytes, %{
filename: "document.pdf",
mime_type: "application/pdf"
})
result.file_id
#=> "files/abc-123"
result.file_uri
#=> "https://generativelanguage.googleapis.com/v1beta/files/abc-123"Google identifies files by resource name (e.g. "files/abc-123"), which is
stored as file_id in the returned FileResult. The file_uri is also
available for use with ContentPart.file_url!/2.
Note: Files uploaded to Gemini expire after 48 hours.
Summary
Functions
Delete a file by its resource name.
Retrieve file metadata by its resource name.
Setup a Google file uploader configuration.
Setup a Google file uploader configuration and return it or raise an error if invalid.
Request a presigned upload URL from Google's resumable upload endpoint (step 1 of 2).
Upload raw file bytes to a presigned upload URL (step 2 of 2).
Types
Functions
Delete a file by its resource name.
file_name must be the Google resource name in the form "files/{id}",
e.g. "files/abc-123". This is the file_id value stored in FileResult.
Retrieve file metadata by its resource name.
file_name must be the Google resource name in the form "files/{id}",
e.g. "files/abc-123". This is the file_id value stored in FileResult.
@spec new(attrs :: map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
Setup a Google file uploader configuration.
Setup a Google file uploader configuration and return it or raise an error if invalid.
@spec request_upload_url(t(), String.t(), String.t(), non_neg_integer()) :: {:ok, String.t()} | {:error, LangChain.LangChainError.t()}
Request a presigned upload URL from Google's resumable upload endpoint (step 1 of 2).
Returns {:ok, upload_url} on success, or {:error, LangChainError.t()} on failure.
The returned URL can be passed to upload_file_bytes/4 to complete the upload, or
forwarded directly to a client (e.g. a browser or mobile app) so it can upload
the file bytes itself without routing them through your server.
@spec upload_file_bytes(t(), String.t(), binary(), non_neg_integer()) :: {:ok, LangChain.FileUploader.FileResult.t()} | {:error, LangChain.LangChainError.t()}
Upload raw file bytes to a presigned upload URL (step 2 of 2).
upload_url is obtained from request_upload_url/4. Returns {:ok, FileResult.t()} on
success, or {:error, LangChainError.t()} on failure.