custom upload file by api #6775

Closed
opened 2026-02-21 18:17:14 -05:00 by yindo · 2 comments
Owner

Originally created by @xiaogu-space on GitHub (Nov 14, 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.11.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I want to upload image by custom tool,this my schema

{
  "openapi": "3.1.0",
  "info": {
    "title": "File Upload API",
    "description": "API for uploading image files",
    "version": "v1.0.0"
  },
  "servers": [
    {
      "url": "http://192.168.60.2:4100/api/upload_image"
    }
  ],
  "paths": {
    "/upload": {
      "post": {
        "summary": "Upload image files",
        "operationId": "uploadFiles",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "img1": {
                    "type": "string",
                    "format": "binary",
                    "description": "The first image file"
                  },
                  "img2": {
                    "type": "string",
                    "format": "binary",
                    "description": "The second image file"
                  }
                },
                "required": ["img1", "img2"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "File upload successful",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "上传成功"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "img1": {
                          "type": "string",
                          "example": "path1"
                        },
                        "img2": {
                          "type": "string",
                          "example": "path2"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid file upload"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {}
  }
}

but get the filed is string not file,like this
image
and I want like this:
image

✔️ Expected Behavior

I want to know how to fix it

Actual Behavior

No response

Originally created by @xiaogu-space on GitHub (Nov 14, 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.11.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I want to upload image by custom tool,this my schema ``` { "openapi": "3.1.0", "info": { "title": "File Upload API", "description": "API for uploading image files", "version": "v1.0.0" }, "servers": [ { "url": "http://192.168.60.2:4100/api/upload_image" } ], "paths": { "/upload": { "post": { "summary": "Upload image files", "operationId": "uploadFiles", "requestBody": { "required": true, "content": { "multipart/form-data": { "schema": { "type": "object", "properties": { "img1": { "type": "string", "format": "binary", "description": "The first image file" }, "img2": { "type": "string", "format": "binary", "description": "The second image file" } }, "required": ["img1", "img2"] } } } }, "responses": { "200": { "description": "File upload successful", "content": { "application/json": { "schema": { "type": "object", "properties": { "message": { "type": "string", "example": "上传成功" }, "data": { "type": "object", "properties": { "img1": { "type": "string", "example": "path1" }, "img2": { "type": "string", "example": "path2" } } } } } } } }, "400": { "description": "Invalid file upload" } } } } }, "components": { "schemas": {} } } ``` but get the filed is string not file,like this ![image](https://github.com/user-attachments/assets/033a58f9-7398-4537-bf00-949080cb5d9f) and I want like this: ![image](https://github.com/user-attachments/assets/de1bdeba-6d82-4ed9-8e29-389a76771edc) ### ✔️ Expected Behavior I want to know how to fix it ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:17:14 -05:00
yindo closed this issue 2026-02-21 18:17:14 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Nov 14, 2024):

@xiaogu-space Hello! I'm here to assist you with any bugs, questions, or contributions. Let's work together to resolve the issue you're facing.

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

  1. how to use api to upload file in 0.11.0 - This discussion is still open and might contain useful insights for handling file uploads in Dify.
  2. How can I upload with multiple files to another server to handle? - This is another open discussion that could provide guidance on handling multiple file uploads.
  3. Help, Custom tool support file as param? - This open discussion might offer solutions for using custom tools with file parameters.

For handling file uploads in Dify's API, ensure that you are using the correct method for multipart/form-data requests. The file_upload method in the DifyClient class is designed to handle such requests by preparing the multipart data correctly. Make sure your API endpoint is configured to accept multipart/form-data and that your request is formatted accordingly [1].

If you are encountering issues with the file being interpreted as a string, double-check that the request is being sent with the correct headers and that the file data is being included as binary in the multipart form. This can often be a source of issues when the server expects a file but receives a string instead.

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Nov 14, 2024): <!-- Greeting --> @xiaogu-space Hello! I'm here to assist you with any bugs, questions, or contributions. Let's work together to resolve the issue you're facing. <!-- Answer --> I found some similar discussions that might be relevant to your issue: 1. [how to use api to upload file in 0.11.0](https://github.com/langgenius/dify/discussions/10659) - This discussion is still open and might contain useful insights for handling file uploads in Dify. 2. [How can I upload with multiple files to another server to handle?](https://github.com/langgenius/dify/discussions/10409) - This is another open discussion that could provide guidance on handling multiple file uploads. 3. [Help, Custom tool support file as param?](https://github.com/langgenius/dify/discussions/9322) - This open discussion might offer solutions for using custom tools with file parameters. For handling file uploads in Dify's API, ensure that you are using the correct method for multipart/form-data requests. The `file_upload` method in the `DifyClient` class is designed to handle such requests by preparing the multipart data correctly. Make sure your API endpoint is configured to accept multipart/form-data and that your request is formatted accordingly <sup>[[1]](https://github.com/langgenius/dify/blob/main/sdks/php-client/dify-client.php)</sup>. If you are encountering issues with the file being interpreted as a string, double-check that the request is being sent with the correct headers and that the file data is being included as binary in the multipart form. This can often be a source of issues when the server expects a file but receives a string instead. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Nov 14, 2024):

This is a bug report template, please use a feature request template instead.

@crazywoola commented on GitHub (Nov 14, 2024): This is a bug report template, please use a feature request template instead.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6775