Unable to upload files to Gemini 2.0 : File not exists in Gemini API

Hello.

I’m trying to use REST file upload API.
First, I’m uploading the file: (it’s in PHP).

        $requestFile = $this->gaiHttpClient->request('POST', '/upload/v1beta/files', [
            'body' => [
                'file' => $input->getFile()
            ]
        ]);

It’s works well - i’m getting a “https://generativelanguage.googleapis.com/v1beta/files/xxxmyfilexxx” URI.
When I’m trying to get the file using API, it’s telling that the file is “ACTIVE”.

But, when I’m trying to do a prompt with this URI using REST "/v1beta/models/gemini-2.0-flash:generateContent, I got this error :

File https://generativelanguage.googleapis.com/v1beta/files/xxxmyfilexxx not exist in the Gemini API.

Does anyone already encoutered this error?

(using inlineData it’s working well but my files are >10mb size so I need to pass an URI)

Hi @findl

Welcome to the forum.

Are you using the FileData property instead of the InlineData? Also, do you specify the MIME type?
Kindly note that files uploaded to File API have a limited lifetime of 48 hours only, and are deleted automatically.

Here’s the payload I generate with my SDK for .NET (built from scratch using the REST calls). Maybe it gives you an idea.

{
  "model" : "models/gemini-2.0-flash-exp",
  "contents" : [ {
    "role" : "user",
    "parts" : [ {
      "text" : "Describe the image with a creative description"
    }, {
      "fileData" : {
        "fileUri" : "https://generativelanguage.googleapis.com/v1beta/files/temb1dhk7gbe",
        "mimeType" : "image/jpeg"
      }
    } ]
  } ]
}

BTW, the limit is 20MB for inline data, as per documentation.

Cheers.

The file header parameter ‘Content Type’ should be set to a file format like ‘video/mp4’ instead of the example ‘Content Type: application/json’ provided by Gemini