Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTF file not supported by the API (UploadFile) #71

Open
BartRennes opened this issue Feb 20, 2025 · 12 comments
Open

RTF file not supported by the API (UploadFile) #71

BartRennes opened this issue Feb 20, 2025 · 12 comments
Labels
bug Something isn't working gemini-api

Comments

@BartRennes
Copy link

BartRennes commented Feb 20, 2025

Hello,

The Gemini SDK supports RTF file, but when using generative-ai with UpLoadFile, i receive this error:
System.NotSupportedException : 'The mime type application/rtf is not supported by the API.'

Do you plan to support RTF file in Upload?

Here the code used:

GenerateContentRequest _request = new GenerateContentRequest(pAction.Prompt);
UploadMediaResponse _responseUpload = await g_ClientAI_Google.UploadFile(pFile, Path.GetFileName(pFile));
_request.AddMedia(_responseUpload.File);

Regards,
Jc

@jochenkirstaetter
Copy link
Contributor

jochenkirstaetter commented Feb 20, 2025

Hi @BartRennes

Thanks for reporting this.
Yes, the Gemini SDK for NET uses a guarding method to check for allowed MIME types.

I'm going to extend it to support the latest ones. Next release, probably in a few hours, will resolve the issue.

Do you have a source / link regarding the currently allowed MIME types? There are probably more than RTF...

Thanks.

@jochenkirstaetter
Copy link
Contributor

jochenkirstaetter commented Feb 20, 2025

Hi @BartRennes

Quickly checking the guarding method reveals that the MIME type "text/rtf" is allowed.
As a quick workaround until the next release you could use this value.

I was using Google's documentation: https://ai.google.dev/gemini-api/docs/document-processing

Cheers.

jochenkirstaetter added a commit that referenced this issue Feb 20, 2025
@jochenkirstaetter
Copy link
Contributor

jochenkirstaetter commented Feb 20, 2025

Hi @BartRennes

The issue has been resolved in release v2.2.6

Thanks again!

@jochenkirstaetter jochenkirstaetter added the enhancement New feature or request label Feb 20, 2025
@BartRennes
Copy link
Author

Wow! Great, thank you, i will test it.

@BartRennes
Copy link
Author

BartRennes commented Feb 20, 2025

Just tested with 2.2.6, and it still doesn't work, here the error message:
Unable to submit request because it has a mimeType parameter with value application/rtf, which is not supported. Update the mimeType and try again.

@jochenkirstaetter
Copy link
Contributor

Hi @BartRennes

OK, but this is now the response from the Gemini API.
I already filled an issue with Google that the MIME type value is not according to the Mozilla Developer Network and it should support both values "application/rtf" as well as "text/rtf".

Well, this means that v2.2.6 just introduced a regression issue and should be reverted. Hmm, silly me not writing a test case...

You have to use "text/rtf" and it should work.

Cheers.

@jochenkirstaetter
Copy link
Contributor

jochenkirstaetter commented Feb 20, 2025

Hi @BartRennes

The File API doesn't care about the MIME type and excepts both.

Image

However, running tests with the identical file using either MIME type produces different HTTP responses.

Image

shows the response you reported in case of "application/rtf" whereas "text/rtf" is accepted and processed.

It's an issue in the Gemini API itself, not the SDK.

Cheers.

@jochenkirstaetter
Copy link
Contributor

Hi @BartRennes

Just pushed release v2.2.7 to provide a workaround to the deficit in the Gemini API.

Cheers.

@jochenkirstaetter
Copy link
Contributor

@BartRennes
Copy link
Author

Thank you for workaround in 2.2.7, good job ;)

@jochenkirstaetter
Copy link
Contributor

jochenkirstaetter commented Feb 20, 2025

Hi @BartRennes

Either use v2.2.7 or extend your line of code

_request.AddMedia(_responseUpload.File);

with the second parameter mimeType to explicitly pass in the override.

Your code should look like this:

var mimeType = _responseUpload.MimeType;
if (mimeType == "application/rtf")
{
  mimeType = "text/rtf";
}
_request.AddMedia(_responseUpload.File, mimeType);

Hope this helps.

@jochenkirstaetter
Copy link
Contributor

Hello @BartRennes

Thanks for the positive feedback and glad it works for you now.

However, the root cause of this issue lies with the Gemini API not accepting the (more) correct MIME type application/rtf. I'm going to revert the workaround as soon as I get a follow-up / change in the API. For now, I'll leave it in.

Again, thanks for reporting this and I'm happy to have it analysed and resolved.

Cheers

@jochenkirstaetter jochenkirstaetter added gemini-api bug Something isn't working and removed enhancement New feature or request labels Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working gemini-api
Projects
None yet
Development

No branches or pull requests

2 participants