Skip to content

fix(gemini): strip data URI prefix from PDF base64 data#14110

Closed
404-Page-Found wants to merge 1 commit intoCherryHQ:v2from
404-Page-Found:fail-to-chat-with-pdf
Closed

fix(gemini): strip data URI prefix from PDF base64 data#14110
404-Page-Found wants to merge 1 commit intoCherryHQ:v2from
404-Page-Found:fail-to-chat-with-pdf

Conversation

@404-Page-Found
Copy link
Copy Markdown
Contributor

What this PR does

Before this PR:
Uploading a PDF file and sending it to Gemini-3.1-pro-preview (or other Gemini models via certain proxies) failed with a "Base64 decoding failed" error because the payload incorrectly included the data:application/pdf;base64, prefix.

After this PR:
The application correctly strips the Data URI prefix from the base64 data for PDF files, ensuring only the raw base64 string is sent to the API.

Fixes #14097

Why we need it and why it was done in this way

Certain API proxies or specific model versions are stricter about the inline_data.data format and do not handle the Data URI prefix. Stripping it ensures compatibility across different providers while remaining compliant with the expected standard of raw base64 for these fields.

The following tradeoffs were made:

  • Added a simple regex check to strip the prefix if present. This adds a negligible overhead but significantly improves compatibility.

The following alternatives were considered:

  • Modifying the backend to handle the prefix, but since this is a frontend-to-SDK interaction, fixing it at the source of parameter preparation is more direct and robust.

Breaking changes

None.

Special notes for your reviewer

I've verified that base64File returns raw base64 in FileStorage.ts, but added this defensive check in fileProcessor.ts to ensure that any data passed to the AI SDK is clean.

Checklist

Release note

Fixed an issue where PDF file uploads to Gemini models failed due to incorrect Base64 encoding format.

@404-Page-Found 404-Page-Found requested a review from a team April 8, 2026 03:11
@DeJeune DeJeune added the v2 label Apr 8, 2026
@DeJeune
Copy link
Copy Markdown
Collaborator

DeJeune commented Apr 8, 2026

Note

This issue/comment/review was translated by Claude.

It can be merged to v1, please revise the PR according to the guidelines.


Original Content

可以合并到v1,根据规范重新改一下pr

@404-Page-Found
Copy link
Copy Markdown
Contributor Author

404-Page-Found commented Apr 8, 2026

Note

This issue/comment/review was translated by Claude.

New PR URL
PR #14134


Original Content

新PR网址
PR #14134

@404-Page-Found 404-Page-Found deleted the fail-to-chat-with-pdf branch April 10, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants