Hierarchy

  • BaseModule
    • Files

Constructors

Methods

Constructors

  • Parameters

    • apiClient: ApiClient

    Returns Files

Methods

  • Retrieves the file information from the service.

    Parameters

    Returns Promise<File>

    The Promise that resolves to the types.File object requested.

    const config: GetFileParameters = {
    name: fileName,
    };
    file = await ai.files.get(config);
    console.log(file.name);
  • Lists all current project files from the service.

    Parameters

    Returns Promise<Pager<File>>

    The paginated results of the list of files

    The following code prints the names of all files from the service, the size of each page is 10.

    const listResponse = await ai.files.list({config: {'pageSize': 10}});
    for await (const file of listResponse) {
    console.log(file.name);
    }
  • Uploads a file asynchronously to the Gemini API. This method is not available in Vertex AI. Supported upload sources:

    • Node.js: File path (string) or Blob object.
    • Browser: Blob object (e.g., File).

    Parameters

    • file: string | Blob

      The string path to the file to be uploaded or a Blob object.

    • Optionalconfig: UploadFileConfig

      Optional parameters specified in the types.UploadFileConfig interface. Optional

    Returns Promise<File>

    A promise that resolves to a types.File object.

    The mimeType can be specified in the config parameter. If omitted:

    • For file path (string) inputs, the mimeType will be inferred from the file extension.
    • For Blob object inputs, the mimeType will be set to the Blob's type property. Somex eamples for file extension to mimeType mapping: .txt -> text/plain .json -> application/json .jpg -> image/jpeg .png -> image/png .mp3 -> audio/mpeg .mp4 -> video/mp4

    This section can contain multiple paragraphs and code examples.

    An error if called on a Vertex AI client.

    An error if the mimeType is not provided and can not be inferred, the mimeType can be provided in the config parameter.

    An error occurs if a suitable upload location cannot be established.

    The following code uploads a file to Gemini API.

    const file = await ai.files.upload('file.txt', {
    mimeType: 'text/plain',
    });
    console.log(file.name);
MMNEPVFCICPMFPCPTTAAATR