Failure to Upload Files with Specified Extensions in Custom File Types #7291

Closed
opened 2026-02-21 18:19:51 -05:00 by yindo · 4 comments
Owner

Originally created by @spr-y on GitHub (Dec 19, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.12.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Specify a single file in the input field of the start node, and set the extension to ".c" in other file types.

  2. Set the file upload type to local.
    image

  3. Start the workflow and specify a local C language source file as the input file.

✔️ Expected Behavior

The C language source file should upload successfully.

Actual Behavior

An error stating "File extension not supported" occurs, preventing the upload.
image

The direct cause is that the getFileExtensionfunction (dify/web/app/components/base/file-uploader/utils.ts) prioritizes obtaining the extension from the MIME type.
On the problematic PCenvironment (Windows 10), the MIME type for *.c was set to "text/plain". As a result, the file extension becomes ".txt" instead of ".c", causing isAllowedFileExtension to return false and triggering the error.

This issue doesnot occur on PCs where the MIME type for *.c is not set.

To resolve this, change the implementation of the getFileExtension function to retrieve from the file name if there's an extension and from the MIME type if there's not.
Since the MIME type of local files is prone to differences depending on each user's environment, it is better to prioritize the file name extension.
However, as the extent of the impact is unknown, this is being registered as an issue.

Originally created by @spr-y on GitHub (Dec 19, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.12.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 1. Specify a single file in the input field of the start node, and set the extension to ".c" in other file types. 2. Set the file upload type to local. ![image](https://github.com/user-attachments/assets/32315f5f-ceb5-42da-a158-3a1f5227a25e) 3. Start the workflow and specify a local C language source file as the input file. ### ✔️ Expected Behavior The C language source file should upload successfully. ### ❌ Actual Behavior An error stating "File extension not supported" occurs, preventing the upload. ![image](https://github.com/user-attachments/assets/1e766f10-740a-4f44-a91a-a441bab2dc99) The direct cause is that the getFileExtensionfunction (dify/web/app/components/base/file-uploader/utils.ts) prioritizes obtaining the extension from the MIME type. On the problematic PCenvironment (Windows 10), the MIME type for *.c was set to "text/plain". As a result, the file extension becomes ".txt" instead of ".c", causing isAllowedFileExtension to return false and triggering the error. This issue doesnot occur on PCs where the MIME type for *.c is not set. To resolve this, change the implementation of the getFileExtension function to retrieve from the file name if there's an extension and from the MIME type if there's not. Since the MIME type of local files is prone to differences depending on each user's environment, it is better to prioritize the file name extension. However, as the extent of the impact is unknown, this is being registered as an issue.
yindo added the 🐞 bug label 2026-02-21 18:19:51 -05:00
yindo closed this issue 2026-02-21 18:19:51 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Dec 19, 2024):

Hello, @spr-y! I'm here to help you with any bugs, questions, or contributions. Let's tackle this issue together!

To resolve the issue of "File extension not supported" when uploading C language source files, you can modify the getFileExtension function to prioritize retrieving the file extension from the file name instead of the MIME type. Here is the updated implementation:

export const getFileExtension = (fileName: string, fileMimetype: string, isRemote?: boolean) => {
  let extension = ''

  if (fileName) {
    const fileNamePair = fileName.split('.')
    const fileNamePairLength = fileNamePair.length

    if (fileNamePairLength > 1)
      extension = fileNamePair[fileNamePairLength - 1]
  }

  if (!extension && fileMimetype) {
    extension = mime.getExtension(fileMimetype) || ''
  }

  if (isRemote)
    extension = ''

  return extension
}

This change ensures that the function first checks the file name for an extension and only falls back to using the MIME type if the file name does not contain an extension. This should help resolve the error by correctly identifying the .c extension from the file name, even if the MIME type is incorrectly set to "text/plain" on certain environments like Windows 10 [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot[bot] commented on GitHub (Dec 19, 2024): <!-- Greeting --> Hello, @spr-y! I'm here to help you with any bugs, questions, or contributions. Let's tackle this issue together! <!-- Answer --> To resolve the issue of "File extension not supported" when uploading C language source files, you can modify the `getFileExtension` function to prioritize retrieving the file extension from the file name instead of the MIME type. Here is the updated implementation: ```typescript export const getFileExtension = (fileName: string, fileMimetype: string, isRemote?: boolean) => { let extension = '' if (fileName) { const fileNamePair = fileName.split('.') const fileNamePairLength = fileNamePair.length if (fileNamePairLength > 1) extension = fileNamePair[fileNamePairLength - 1] } if (!extension && fileMimetype) { extension = mime.getExtension(fileMimetype) || '' } if (isRemote) extension = '' return extension } ``` This change ensures that the function first checks the file name for an extension and only falls back to using the MIME type if the file name does not contain an extension. This should help resolve the error by correctly identifying the `.c` extension from the file name, even if the MIME type is incorrectly set to "text/plain" on certain environments like Windows 10 <sup>[[1]](https://github.com/langgenius/dify/blob/main/web/app/components/base/file-uploader/utils.ts)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/90863554-2633-4c9e-9ebf-01fca9e85b04?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/90863554-2633-4c9e-9ebf-01fca9e85b04?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/90863554-2633-4c9e-9ebf-01fca9e85b04?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/90863554-2633-4c9e-9ebf-01fca9e85b04?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/90863554-2633-4c9e-9ebf-01fca9e85b04?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/90863554-2633-4c9e-9ebf-01fca9e85b04?feedback_type=other)</sup>
Author
Owner

@spr-y commented on GitHub (Dec 19, 2024):

Hello @dosu,
I believe that fix will solve the problem.
Unfortunately, I don't have a development environment, so I can't verify it.
Is there anyone who can check?

@spr-y commented on GitHub (Dec 19, 2024): Hello @dosu, I believe that fix will solve the problem. Unfortunately, I don't have a development environment, so I can't verify it. Is there anyone who can check?
Author
Owner

@dosubot[bot] commented on GitHub (Dec 19, 2024):

This issue seems to need your specialized knowledge, @takatost, could you step in and provide your guidance?

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot[bot] commented on GitHub (Dec 19, 2024): <!-- Answer --> This issue seems to need your specialized knowledge, @takatost, could you step in and provide your guidance? <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/be0ac7e5-f890-418a-84ed-8aa0e5dd49c3?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/be0ac7e5-f890-418a-84ed-8aa0e5dd49c3?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/be0ac7e5-f890-418a-84ed-8aa0e5dd49c3?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/be0ac7e5-f890-418a-84ed-8aa0e5dd49c3?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/be0ac7e5-f890-418a-84ed-8aa0e5dd49c3?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/be0ac7e5-f890-418a-84ed-8aa0e5dd49c3?feedback_type=other)</sup>
Author
Owner

@crazywoola commented on GitHub (Dec 25, 2024):

Please upgrade to latest version to see if this persists.

@crazywoola commented on GitHub (Dec 25, 2024): Please upgrade to latest version to see if this persists.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#7291