LLM cannot upload files when calling large models #5771

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

Originally created by @yunfeng13 on GitHub (Sep 24, 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.8.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

LLM cannot upload files when calling large models. Our current requirement is to be able to upload files, but why is there no corresponding upload file found on diffy? The large model can only upload images.

✔️ Expected Behavior

LLM cannot upload files when calling large models. Our current requirement is to be able to upload files, but why is there no corresponding upload file found on diffy? The large model can only upload images.

Actual Behavior

LLM cannot upload files when calling large models. Our current requirement is to be able to upload files, but why is there no corresponding upload file found on diffy? The large model can only upload images.

Originally created by @yunfeng13 on GitHub (Sep 24, 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.8.3 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce LLM cannot upload files when calling large models. Our current requirement is to be able to upload files, but why is there no corresponding upload file found on diffy? The large model can only upload images. ### ✔️ Expected Behavior LLM cannot upload files when calling large models. Our current requirement is to be able to upload files, but why is there no corresponding upload file found on diffy? The large model can only upload images. ### ❌ Actual Behavior LLM cannot upload files when calling large models. Our current requirement is to be able to upload files, but why is there no corresponding upload file found on diffy? The large model can only upload images.
yindo added the 🐞 bug label 2026-02-21 18:12:31 -05:00
yindo closed this issue 2026-02-21 18:12:31 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 24, 2024):

I found some similar discussions and an issue that might be relevant to your problem:

  1. PDF or text files upload [1]
  2. Upload files and return files in the conversation [2]
  3. Getting status of 413 (Request Entity Too Large) with large files even though I increased size in .env [3]
  4. Invalid upload file (closed) [4]

The issue with "Invalid upload file" was resolved by ensuring that files are uploaded correctly using the file_upload method and then using the returned file IDs in the create_chat_message method. Here is an example of how you can do this:

  1. Upload the files using the file_upload method:

    <?php
    
    require 'vendor/autoload.php';
    
    use GuzzleHttp\Client;
    
    class DifyClient {
        // ... (existing code)
    
        public function file_upload($user, $files) {
            $data = ['user' => $user];
            $options = [
                'multipart' => $this->prepareMultipart($data, $files)
            ];
    
            return $this->file_client->request('POST', 'files/upload', $options);
        }
    
        protected function prepareMultipart($data, $files) {
            $multipart = [];
            foreach ($data as $key => $value) {
                $multipart[] = [
                    'name' => $key,
                    'contents' => $value
                ];
            }
    
            foreach ($files as $file) {
                $multipart[] = [
                    'name' => 'file',
                    'contents' => fopen($file['tmp_name'], 'r'),
                    'filename' => $file['name']
                ];
            }
    
            return $multipart;
        }
    }
    
    class ChatClient extends DifyClient {
        public function create_chat_message($inputs, $query, $user, $response_mode = 'blocking', $conversation_id = null, $files = null) {
            $data = [
                'inputs' => $inputs,
                'query' => $query,
                'user' => $user,
                'response_mode' => $response_mode,
            ];
            if ($conversation_id) {
                $data['conversation_id'] = $conversation_id;
            }
            if ($files) {
                $data['files'] = $files;
            }
    
            return $this->send_request('POST', 'chat-messages', $data, null, $response_mode === 'streaming');
        }
    }
    
    // Usage example
    $api_key = 'your_api_key';
    $base_url = 'https://api.dify.ai/v1/';
    $user = 'your_user_id';
    $files = [
        ['tmp_name' => '/path/to/file1.txt', 'name' => 'file1.txt'],
        ['tmp_name' => '/path/to/file2.txt', 'name' => 'file2.txt']
    ];
    
    $client = new ChatClient($api_key, $base_url);
    
    // Step 1: Upload files
    $response = $client->file_upload($user, $files);
    $file_ids = json_decode($response->getBody(), true)['file_ids'];
    
    // Step 2: Create chat message with file IDs
    $inputs = ['input1' => 'value1'];
    $query = 'Your query here';
    $response_mode = 'blocking';
    $conversation_id = null;
    
    $response = $client->create_chat_message($inputs, $query, $user, $response_mode, $conversation_id, $file_ids);
    echo $response->getBody();
    
  2. Ensure the files being uploaded are of the correct type and format as expected by the Dify API. The supported image formats are png, jpg, jpeg, webp, and gif.

  3. Set the transfer_method parameter to local_file when using the uploaded file ID in the create_chat_message method. This ensures that the API correctly interprets the file ID as a locally uploaded file.

By following these steps, you should be able to resolve the file upload issue with large models [4].

Additionally, the supported file types for uploads in Dify are:

  • Text files: txt, markdown, md
  • Document files: pdf, html, htm, xlsx, xls, docx, csv, eml, msg, pptx, ppt, xml, epub
  • Image files: jpg, jpeg, png, webp, gif, svg (both lowercase and uppercase extensions are supported)

The size limits for file uploads are:

  • For image files: 10MB
  • For other files: 15MB
  • For knowledge documents: 15MB per document, with a limit of 100 total documents [5][6][7][8].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 24, 2024): <!-- Answer --> I found some similar discussions and an issue that might be relevant to your problem: 1. [PDF or text files upload](https://github.com/langgenius/dify/discussions/8603) <sup>[[1]](https://github.com/langgenius/dify/discussions/8603)</sup> 2. [Upload files and return files in the conversation](https://github.com/langgenius/dify/discussions/6781) <sup>[[2]](https://github.com/langgenius/dify/discussions/6781)</sup> 3. [Getting status of 413 (Request Entity Too Large) with large files even though I increased size in .env](https://github.com/langgenius/dify/discussions/8277) <sup>[[3]](https://github.com/langgenius/dify/discussions/8277)</sup> 4. [Invalid upload file](https://github.com/langgenius/dify/issues/8573) (closed) <sup>[[4]](https://github.com/langgenius/dify/issues/8573)</sup> The issue with "Invalid upload file" was resolved by ensuring that files are uploaded correctly using the `file_upload` method and then using the returned file IDs in the `create_chat_message` method. Here is an example of how you can do this: 1. **Upload the files using the `file_upload` method**: ```php <?php require 'vendor/autoload.php'; use GuzzleHttp\Client; class DifyClient { // ... (existing code) public function file_upload($user, $files) { $data = ['user' => $user]; $options = [ 'multipart' => $this->prepareMultipart($data, $files) ]; return $this->file_client->request('POST', 'files/upload', $options); } protected function prepareMultipart($data, $files) { $multipart = []; foreach ($data as $key => $value) { $multipart[] = [ 'name' => $key, 'contents' => $value ]; } foreach ($files as $file) { $multipart[] = [ 'name' => 'file', 'contents' => fopen($file['tmp_name'], 'r'), 'filename' => $file['name'] ]; } return $multipart; } } class ChatClient extends DifyClient { public function create_chat_message($inputs, $query, $user, $response_mode = 'blocking', $conversation_id = null, $files = null) { $data = [ 'inputs' => $inputs, 'query' => $query, 'user' => $user, 'response_mode' => $response_mode, ]; if ($conversation_id) { $data['conversation_id'] = $conversation_id; } if ($files) { $data['files'] = $files; } return $this->send_request('POST', 'chat-messages', $data, null, $response_mode === 'streaming'); } } // Usage example $api_key = 'your_api_key'; $base_url = 'https://api.dify.ai/v1/'; $user = 'your_user_id'; $files = [ ['tmp_name' => '/path/to/file1.txt', 'name' => 'file1.txt'], ['tmp_name' => '/path/to/file2.txt', 'name' => 'file2.txt'] ]; $client = new ChatClient($api_key, $base_url); // Step 1: Upload files $response = $client->file_upload($user, $files); $file_ids = json_decode($response->getBody(), true)['file_ids']; // Step 2: Create chat message with file IDs $inputs = ['input1' => 'value1']; $query = 'Your query here'; $response_mode = 'blocking'; $conversation_id = null; $response = $client->create_chat_message($inputs, $query, $user, $response_mode, $conversation_id, $file_ids); echo $response->getBody(); ``` 2. **Ensure the files being uploaded are of the correct type and format** as expected by the Dify API. The supported image formats are png, jpg, jpeg, webp, and gif. 3. **Set the `transfer_method` parameter to `local_file`** when using the uploaded file ID in the `create_chat_message` method. This ensures that the API correctly interprets the file ID as a locally uploaded file. By following these steps, you should be able to resolve the file upload issue with large models <sup>[[4]](https://github.com/langgenius/dify/issues/8573)</sup>. Additionally, the supported file types for uploads in Dify are: - Text files: `txt`, `markdown`, `md` - Document files: `pdf`, `html`, `htm`, `xlsx`, `xls`, `docx`, `csv`, `eml`, `msg`, `pptx`, `ppt`, `xml`, `epub` - Image files: `jpg`, `jpeg`, `png`, `webp`, `gif`, `svg` (both lowercase and uppercase extensions are supported) The size limits for file uploads are: - For image files: 10MB - For other files: 15MB - For knowledge documents: 15MB per document, with a limit of 100 total documents <sup>[[5]](https://github.com/langgenius/dify/blob/main/api/services/file_service.py)</sup><sup>[[6]](https://github.com/langgenius/dify-docs/blob/main/en/guides/application-orchestrate/llms-use-faq.md)</sup><sup>[[7]](https://github.com/langgenius/dify-docs/blob/main/en/getting-started/install-self-hosted/environments.md)</sup><sup>[[8]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/getting-started/install-self-hosted/environments.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@yunfeng13 commented on GitHub (Sep 24, 2024):

@StudyingLover @dosu My question is does dify support LLM uploading files? Now I only find uploaded images.

@yunfeng13 commented on GitHub (Sep 24, 2024): @StudyingLover @dosu My question is does dify support LLM uploading files? Now I only find uploaded images.
Author
Owner

@crazywoola commented on GitHub (Sep 24, 2024):

First of all, this is bug only report. You need to distinguish the feature and bug by providing error logs.
Secondly, you should search existing issues before opening it.
Thirdly, https://github.com/langgenius/dify/issues/5346 this issue is pinned in the issues pages.

@crazywoola commented on GitHub (Sep 24, 2024): First of all, this is bug only report. You need to distinguish the feature and bug by providing error logs. Secondly, you should search existing issues before opening it. Thirdly, https://github.com/langgenius/dify/issues/5346 this issue is pinned in the issues pages.
Author
Owner

@dosubot[bot] commented on GitHub (Sep 24, 2024):

Yes, Dify supports uploading files other than images. You can upload various file types such as txt, markdown, md, pdf, html, htm, xlsx, xls, docx, csv, eml, msg, pptx, ppt, xml, and epub. The maximum file size for uploads is 15MB for non-image files and 10MB for image files [1][2].

To upload files using the Dify API, you can use the following endpoints:

  1. Create documents from files

    • Endpoint: POST https://api.dify.ai/v1/datasets/{dataset_id}/document/create_by_file
    • Example:
      curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create_by_file' \
      --header 'Authorization: Bearer {api_key}' \
      --form 'data="{
          \"indexing_technique\": \"high_quality\",
          \"process_rule\": {
              \"rules\": {
                  \"pre_processing_rules\": [{
                      \"id\": \"remove_extra_spaces\",
                      \"enabled\": true
                  }, {
                      \"id\": \"remove_urls_emails\",
                      \"enabled\": true
                  }],
                  \"segmentation\": {
                      \"separator\": \"###\",
                      \"max_tokens\": 500
                  }
              },
              \"mode\": \"custom\"
          }
      }";type=text/plain' \
      --form 'file=@"/path/to/file"'
      
  2. Update a document from a file

    • Endpoint: POST https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/update_by_file
    • Example:
      curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/update_by_file' \
      --header 'Authorization: Bearer {api_key}' \
      --form 'data="{
          \"name\": \"Dify\",
          \"indexing_technique\": \"high_quality\",
          \"process_rule\": {
              \"rules\": {
                  \"pre_processing_rules\": [{
                      \"id\": \"remove_extra_spaces\",
                      \"enabled\": true
                  }, {
                      \"id\": \"remove_urls_emails\",
                      \"enabled\": true
                  }],
                  \"segmentation\": {
                      \"separator\": \"###\",
                      \"max_tokens\": 500
                  }
              },
              \"mode\": \"custom\"
          }
      }";type=text/plain' \
      --form 'file=@"/path/to/file"'
      

These endpoints support various file types and ensure that your files are processed and indexed correctly [3][4].

For more detailed examples and configurations, you can refer to the Dify documentation.

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 24, 2024): <!-- Answer --> Yes, Dify supports uploading files other than images. You can upload various file types such as `txt`, `markdown`, `md`, `pdf`, `html`, `htm`, `xlsx`, `xls`, `docx`, `csv`, `eml`, `msg`, `pptx`, `ppt`, `xml`, and `epub`. The maximum file size for uploads is 15MB for non-image files and 10MB for image files <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/services/file_service.py)</sup><sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/en/guides/application-orchestrate/llms-use-faq.md)</sup>. To upload files using the Dify API, you can use the following endpoints: 1. **Create documents from files** - **Endpoint:** `POST https://api.dify.ai/v1/datasets/{dataset_id}/document/create_by_file` - **Example:** ```bash curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create_by_file' \ --header 'Authorization: Bearer {api_key}' \ --form 'data="{ \"indexing_technique\": \"high_quality\", \"process_rule\": { \"rules\": { \"pre_processing_rules\": [{ \"id\": \"remove_extra_spaces\", \"enabled\": true }, { \"id\": \"remove_urls_emails\", \"enabled\": true }], \"segmentation\": { \"separator\": \"###\", \"max_tokens\": 500 } }, \"mode\": \"custom\" } }";type=text/plain' \ --form 'file=@"/path/to/file"' ``` 2. **Update a document from a file** - **Endpoint:** `POST https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/update_by_file` - **Example:** ```bash curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/update_by_file' \ --header 'Authorization: Bearer {api_key}' \ --form 'data="{ \"name\": \"Dify\", \"indexing_technique\": \"high_quality\", \"process_rule\": { \"rules\": { \"pre_processing_rules\": [{ \"id\": \"remove_extra_spaces\", \"enabled\": true }, { \"id\": \"remove_urls_emails\", \"enabled\": true }], \"segmentation\": { \"separator\": \"###\", \"max_tokens\": 500 } }, \"mode\": \"custom\" } }";type=text/plain' \ --form 'file=@"/path/to/file"' ``` These endpoints support various file types and ensure that your files are processed and indexed correctly <sup>[[3]](https://github.com/langgenius/dify-docs/blob/main/en/guides/knowledge-base/maintain-dataset-via-api.md)</sup><sup>[[4]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/features/datasets/maintain-dataset-via-api.md)</sup>. For more detailed examples and configurations, you can refer to the Dify documentation. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5771