fix: detect uploaded file type for uppercase file extensions#6481
fix: detect uploaded file type for uppercase file extensions#6481sanidhyasin wants to merge 2 commits into
Conversation
mapExtToInputField matched extensions with a case-sensitive switch, so an uppercase extension like ".PDF" fell through to the default 'txtFile' and the uploaded file was handled by the text loader instead of the correct loader (e.g. the PDF loader). Lowercase the extension before matching so file type detection is case-insensitive. Also fix the MIME-type fallback in createFileAttachment: the branch assigned fileInputFieldFromExt (which is always 'txtFile' there) instead of fileInputFieldFromMimeType, so the fallback never selected the field derived from the MIME type. Fixes FlowiseAI#5029
There was a problem hiding this comment.
Code Review
This pull request introduces case-insensitivity to the mapExtToInputField utility function by converting the input extension to lowercase, accompanied by comprehensive unit tests. It also fixes a bug in createFileAttachment where the fallback assignment incorrectly used the extension-based field instead of the mime-type-based field. Feedback suggests adding a nullish check (ext == null) in mapExtToInputField to prevent potential runtime TypeError crashes if the extension is null or undefined.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Use optional chaining so a null/undefined/empty extension falls through to the existing 'txtFile' default instead of throwing on .toLowerCase(), while keeping the string return type intact for callers.
|
Thanks for the review. Addressed in I guarded the nullish case with optional chaining ( if (fileInputFieldFromExt !== 'txtFile') {
fileInputField = fileInputFieldFromExt // would become `undefined`
}With optional chaining, a |
Description
Uploading a file whose name ends with an uppercase extension (e.g.
report.PDF) does not work — the file is processed by the plain-text loader instead of the correct one (the PDF loader), producing garbled/empty content. Renaming the file to a lowercase extension (report.pdf) works around it.Root cause
mapExtToInputField(inpackages/components/src/utils.ts) matches the extension with a case-sensitiveswitch.path.extname('report.PDF')returns'.PDF', which does not match the'.pdf'case and falls through to the default'txtFile', so the wrong file loader input field is selected.The MIME-type fallback in
createFileAttachmentthat should have caught this was also broken by a copy-paste bug: in theelse if (fileInputFieldFromMimeType !== 'txtFile')branch it assignedfileInputFieldFromExt(which is always'txtFile'in that branch) instead offileInputFieldFromMimeType, so the MIME-derived field was never used.Changes
mapExtToInputField: lowercase the extension before matching, making file-type detection case-insensitive. This is the shared helper used by full file upload, the document store, and chat uploads, so the fix applies consistently across all of them.createFileAttachment: usefileInputFieldFromMimeTypein the MIME-type fallback branch so the field derived from the MIME type is actually selected when the extension is unrecognized.mapExtToInputFieldcovering lowercase, uppercase, mixed-case, and unknown extensions.Note: the upload security validator (
validateMimeTypeAndExtensionMatch) already normalizes the extension to lowercase, so uppercase files were not rejected — only mis-routed. No change to validation behavior.Fixes #5029
How to reproduce / verify
.PDF(uppercase)..pdffile.