fix(server): use fileInputFieldFromMimeType in MIME type fallback branch#6007
fix(server): use fileInputFieldFromMimeType in MIME type fallback branch#6007wishhyt wants to merge 1 commit intoFlowiseAI:mainfrom
Conversation
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
Summary of ChangesHello, 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
|
@0xi4o is this valid? I traced back the history of the file it didnt looks like we accidentally changed it before |
|
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: After PR #3288 (current code): 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. |
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:
Changes
Changed fileInputField = fileInputFieldFromExt to fileInputField = fileInputFieldFromMimeType in the else if (fileInputFieldFromMimeType !== 'txtFile') branch across all 4 files.
How to reproduce the bug