Skip to content

fix(server): use fileInputFieldFromMimeType in MIME type fallback branch#6007

Open
wishhyt wants to merge 1 commit intoFlowiseAI:mainfrom
wishhyt:bugfix/fix-file-input-field-assignment
Open

fix(server): use fileInputFieldFromMimeType in MIME type fallback branch#6007
wishhyt wants to merge 1 commit intoFlowiseAI:mainfrom
wishhyt:bugfix/fix-file-input-field-assignment

Conversation

@wishhyt
Copy link
Contributor

@wishhyt wishhyt commented Mar 18, 2026

Summary

When processing file uploads, the code determines the correct input field using a two-step fallback: first by file extension, then by MIME type. However, in the MIME type fallback branch (else if), the code incorrectly assigns fileInputFieldFromExt (which is 'txtFile' at that point) instead of fileInputFieldFromMimeType.

This means when a file has an unrecognized extension but a recognized MIME type, the MIME type detection result is silently ignored and the file is always treated as a text file.

The same copy-paste bug exists in 4 files:

  • packages/server/src/utils/buildChatflow.ts
  • packages/server/src/utils/createAttachment.ts
  • packages/server/src/services/documentstore/index.ts
  • packages/server/src/utils/upsertVector.ts

Changes

Changed fileInputField = fileInputFieldFromExt to fileInputField = fileInputFieldFromMimeType in the else if (fileInputFieldFromMimeType !== 'txtFile') branch across all 4 files.

How to reproduce the bug

  • Upload a file with an unusual extension but a standard MIME type (e.g., a .dat file with image/png MIME type)
  • The file is incorrectly classified as txtFile instead of the correct image input field

When file extension is unrecognized but MIME type is recognized, the code
should fall back to the MIME-type-based input field. However, a copy-paste
error caused it to assign `fileInputFieldFromExt` (which equals 'txtFile')
instead of `fileInputFieldFromMimeType`, effectively ignoring the MIME type
detection result.

This bug was duplicated across four files:
- packages/server/src/utils/buildChatflow.ts
- packages/server/src/utils/createAttachment.ts
- packages/server/src/services/documentstore/index.ts
- packages/server/src/utils/upsertVector.ts

Made-with: Cursor
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical bug in the server's file upload processing logic. Previously, a copy-paste error caused the system to ignore valid MIME type detections for files with unknown extensions, leading to their incorrect classification as plain text. The fix ensures that the MIME type fallback correctly determines the appropriate input field, improving the accuracy of file handling and preventing misinterpretation of uploaded content.

Highlights

  • Bug Fix: Addressed a critical bug where file uploads with unrecognized extensions but recognized MIME types were incorrectly classified as plain text files.
  • MIME Type Fallback Correction: Ensured that the MIME type fallback mechanism correctly assigns the appropriate fileInputField when the file extension is not recognized, preventing misclassification.
  • Code Consistency: Applied the necessary fix across four server-side utility files that shared the same copy-paste error in their file processing logic.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request correctly addresses a bug where the fileInputField was incorrectly assigned fileInputFieldFromExt instead of fileInputFieldFromMimeType in the MIME type fallback branch. The fix has been applied consistently across all four identified files, ensuring that files with unrecognized extensions but recognized MIME types are now correctly classified. This is a critical fix for file upload functionality.

@HenryHengZJ
Copy link
Contributor

@0xi4o is this valid? I traced back the history of the file it didnt looks like we accidentally changed it before

@wishhyt
Copy link
Contributor Author

wishhyt commented Mar 19, 2026

Hi @HenryHengZJ , thanks for looking into this!

You're right that the code wasn't accidentally changed — the bug was introduced in the original commit that added this logic. Specifically, it was introduced in PR #3288 (commit 04e8d02, Sep 30, 2024), which refactored the file input field detection from a simple MIME-type-only approach to a two-step "extension first, MIME type fallback" approach.

Before PR #3288:

const fileInputField = mapMimeTypeToInputField(file.mimetype)
overrideConfig[fileInputField] = storagePath

After PR #3288 (current code):

let fileInputField = 'txtFile'

if (fileInputFieldFromExt !== 'txtFile') {
    fileInputField = fileInputFieldFromExt          // ← extension matched
} else if (fileInputFieldFromMimeType !== 'txtFile') {
    fileInputField = fileInputFieldFromExt           // ← BUG: should be fileInputFieldFromMimeType
}

Why the else if branch is effectively dead code:

Entering the else if means the if condition failed, so fileInputFieldFromExt === 'txtFile'. Assigning fileInputField = fileInputFieldFromExt is equivalent to fileInputField = 'txtFile', which is already the default. The MIME type detection result is never used.

The intent of the two-step logic was clearly: try extension → fall back to MIME type → default to 'txtFile'. The variable name in the fallback line should be fileInputFieldFromMimeType, not fileInputFieldFromExt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants