Android SDK - video uri issue "Invalid or unsupported file uri"

Hi,
I tried to use the Gemini Android SDK (v. 0.6.0) to prompt something about a video.
Here is my code :

private val generativeModel = GenerativeModel(
        modelName = "gemini-1.5-pro",
        apiKey = appConfig.geminiApiKey,
    )

val inputContent = content {
            fileData(videoUri, "video/mp4")
            text(prompt)
        }
val response = generativeModel.generateContent(inputContent)

I tried with lot of video URI : videos from the Android Photo picker, but also videos created by the app using a dedicated file:

val outputFile = File(filesDir, "temp_video2.mp4")
val uri = outputFile.path

I tried:
outputFile.toURI().rawPath
outputFile.canonicalPath
outputFile.absolutePath
outputFile.path
outputFile.toURI().path

I even tried to send a video URL from the web as video URI…

but I have always the same error:

com.google.ai.client.generativeai.type.ServerException: Invalid or unsupported file uri:

Does anyone understand how to send the file ?
I saw someone advice to use File API, but it doesn’t look available on the Android SDK…

As you’ve see, fileData() doesn’t support video directly.

As you’ve also seen, the Android library doesn’t support the File API yet either. As it says if you Show Code in AI Studio:

// NOTE: Your prompt contains media inputs, which are not currently supported by
// the Android SDK. The code snippet below may be incomplete.

If you’re familiar with working with a REST API, you can probably implement the File API yourself, but I’m not aware of any other solution at this time.

@afirstenberg Thank you for your answer.
I tried to find the REST documentation for the File API but it doesn’t exist. I just found about Python, Go and NodeJS clients :confused:
Do you know how to find the REST API doc ?

The REST documentation is at Method: media.upload  |  Google AI for Developers  |  Google for Developers

(I will warn you - it is not exactly straightforward to understand.)

Ok thank you so much !

@afirstenberg indeed it’s not crystal clear :sweat_smile:
Am I supposed to use gRPC protocol ?

No, they just use gRPC terminology to specify the path. You can do it with just regular HTTP REST calls.