fix: file loader not picking up uploaded files from API upsert request#6173
fix: file loader not picking up uploaded files from API upsert request#6173BOOPATB wants to merge 3 commits intoFlowiseAI:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request fixes a copy-paste error in upsertVector.ts where the incorrect variable was assigned to fileInputField. The review feedback suggests further improving this logic by adding truthiness checks to prevent assigning falsy values, ensuring a more robust fallback to the default field name.
| if (fileInputFieldFromExt !== 'txtFile') { | ||
| fileInputField = fileInputFieldFromExt | ||
| } else if (fileInputFieldFromMimeType !== 'txtFile') { | ||
| fileInputField = fileInputFieldFromExt | ||
| fileInputField = fileInputFieldFromMimeType | ||
| } |
There was a problem hiding this comment.
While this change correctly fixes the copy-paste error, the logic should also ensure that fileInputField is not assigned a falsy value (such as undefined or null) if the mapping functions fail to return a valid string. Adding a truthiness check provides a more robust fallback mechanism to the default 'txtFile', preventing potential issues with incorrect field mapping in overrideConfig. This implementation uses an if/else if chain, which is preferred for a small number of conditional branches to maintain readability.
| if (fileInputFieldFromExt !== 'txtFile') { | |
| fileInputField = fileInputFieldFromExt | |
| } else if (fileInputFieldFromMimeType !== 'txtFile') { | |
| fileInputField = fileInputFieldFromExt | |
| fileInputField = fileInputFieldFromMimeType | |
| } | |
| if (fileInputFieldFromExt && fileInputFieldFromExt !== 'txtFile') { | |
| fileInputField = fileInputFieldFromExt | |
| } else if (fileInputFieldFromMimeType && fileInputFieldFromMimeType !== 'txtFile') { | |
| fileInputField = fileInputFieldFromMimeType | |
| } |
References
- Use a default (fallback) implementation unless the specific implementation has meaningfully different behavior or provides better error messages.
- For a small number of conditional branches, an if/else if chain may be preferred over a map lookup to maintain readability.
Problem
Fixes #6102
When uploading a file via the
/api/v1/vector/upsert/:idAPI endpoint usingmultipart/form-data, the file is silently ignored and nothing gets indexed.
This regression was introduced in 3.1.x.
Root Cause
In
packages/server/src/utils/upsertVector.ts, the logic that determineswhich input field to use for the uploaded file had a copy-paste bug:
When a file's extension maps to
txtFilebut its MIME type correctlyidentifies the file type, the code was incorrectly using
fileInputFieldFromExt(which is
txtFile) instead offileInputFieldFromMimeType. This caused thefile to be stored under the wrong input field key, so the File Loader node
never received it.
Changes
packages/server/src/utils/upsertVector.ts: one-line fix, usefileInputFieldFromMimeTypeinstead offileInputFieldFromExtin the else-if branch