Skip to content

Files

Latest commit

 

History

History
123 lines (80 loc) · 2.13 KB

File metadata and controls

123 lines (80 loc) · 2.13 KB

google.generativeai.upload_file

View source on GitHub

Calls the API to upload a file using a supported file service.

google.generativeai.upload_file(
    path: (str | pathlib.Path | os.PathLike | IOBase),
    *,
    mime_type: (str | None) = None,
    name: (str | None) = None,
    display_name: (str | None) = None,
    resumable: bool = True
) -> file_types.File

Args

path

The path to the file or a file-like object (e.g., BytesIO) to be uploaded.

mime_type

The MIME type of the file. If not provided, it will be inferred from the file extension.

name

The name of the file in the destination (e.g., 'files/sample-image'). If not provided, a system generated ID will be created.

display_name

Optional display name of the file.

resumable

Whether to use the resumable upload protocol. By default, this is enabled. See details at https://googleapis.github.io/google-api-python-client/docs/epy/googleapiclient.http.MediaFileUpload-class.html#resumable

Returns

file_types.File

The response of the uploaded file.