how to use api to upload file in 0.11.0 #6747

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

Originally created by @xs818818 on GitHub (Nov 13, 2024).

Self Checks

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

Provide a description of requested docs changes

when i ues

curl -X POST 'http://*/v1/files/upload' \
--header 'Authorization: Bearer app-5fnWbo7I35vn36HGcXRPdLbf' \
--form 'file=@"/home/xs/1.pdf";type=document/[pdf]' \
--form 'user=xs818818'
curl -X POST 'http://**/v1/workflows/run' \
--header 'Authorization: Bearer app-5fnWbo7I35vn36HGcXRPdLbf' \
--header 'Content-Type: application/json' \
--data-raw '{
    "inputs": {},
    "response_mode": "blocking",
    "user": "xs818818",
    "files": [
        {
            "type": "document/pdf",
            "transfer_method": "local_file",
            "upload_file_id": "2eb7c67e-1a5c-4a38-9ddf-f18ed13a7cf8"
        }
    ]
}' 
{"code": "invalid_param", "message": "file is required in input form", "status": 400}
Originally created by @xs818818 on GitHub (Nov 13, 2024). ### Self Checks - [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 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. ### Provide a description of requested docs changes when i ues ``` curl -X POST 'http://*/v1/files/upload' \ --header 'Authorization: Bearer app-5fnWbo7I35vn36HGcXRPdLbf' \ --form 'file=@"/home/xs/1.pdf";type=document/[pdf]' \ --form 'user=xs818818' ``` ``` curl -X POST 'http://**/v1/workflows/run' \ --header 'Authorization: Bearer app-5fnWbo7I35vn36HGcXRPdLbf' \ --header 'Content-Type: application/json' \ --data-raw '{ "inputs": {}, "response_mode": "blocking", "user": "xs818818", "files": [ { "type": "document/pdf", "transfer_method": "local_file", "upload_file_id": "2eb7c67e-1a5c-4a38-9ddf-f18ed13a7cf8" } ] }' ``` ``` {"code": "invalid_param", "message": "file is required in input form", "status": 400} ```
yindo added the 📚 documentation label 2026-02-21 18:17:05 -05:00
yindo closed this issue 2026-02-21 18:17:05 -05:00
Author
Owner

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

To upload a file using the API in version 0.11.0, you should ensure that the file is correctly included in the form data of your request. The error message "file is required in input form" with status 400 indicates that the file was not properly included. Here's a correct example of how to use the curl command for file uploads:

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"' \
--form 'user="abc-123"'

Make sure that the --form 'file=@"/path/to/file"' part of the curl command is correctly pointing to the file you want to upload. The path should be valid, and the file should exist at that location. Additionally, ensure that the request is formatted as multipart/form-data, as this is required for file uploads. Also, verify that the file type is supported, as the API currently supports specific file types such as txt, markdown, md, pdf, html, htm, xlsx, docx, and csv [1].

If you continue to encounter issues, double-check the file path and ensure that the file is accessible from the location specified in your curl command.

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Nov 13, 2024): <!-- Answer --> To upload a file using the API in version 0.11.0, you should ensure that the file is correctly included in the form data of your request. The error message "file is required in input form" with status 400 indicates that the file was not properly included. Here's a correct example of how to use the curl command for file uploads: ```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"' \ --form 'user="abc-123"' ``` Make sure that the `--form 'file=@"/path/to/file"'` part of the curl command is correctly pointing to the file you want to upload. The path should be valid, and the file should exist at that location. Additionally, ensure that the request is formatted as `multipart/form-data`, as this is required for file uploads. Also, verify that the file type is supported, as the API currently supports specific file types such as txt, markdown, md, pdf, html, htm, xlsx, docx, and csv <sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/guides/knowledge-base/maintain-dataset-via-api.md)</sup>. If you continue to encounter issues, double-check the file path and ensure that the file is accessible from the location specified in your curl command. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@xs818818 commented on GitHub (Nov 13, 2024):

curl --location --request POST 'https://api.dify.ai/v1/datasets/98915774-f515-4ae7-9fa5-5a85f7fc58d3/document/create_by_file' \

--header 'Authorization: Bearer dataset-rrCiMDKqsZJ5nyiue70ZJUkl'
--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=@"/home/xs/1.pdf"'
--form 'user="xs818818@163.com"'
{"code": "invalid_param", "message": "Expecting property name enclosed in double quotes: line 1 column 2 (char 1)", "status": 400}

@xs818818 commented on GitHub (Nov 13, 2024): curl --location --request POST 'https://api.dify.ai/v1/datasets/98915774-f515-4ae7-9fa5-5a85f7fc58d3/document/create_by_file' \ > --header 'Authorization: Bearer dataset-rrCiMDKqsZJ5nyiue70ZJUkl' \ > --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=@"/home/xs/1.pdf"' \ > --form 'user="xs818818@163.com"' {"code": "invalid_param", "message": "Expecting property name enclosed in double quotes: line 1 column 2 (char 1)", "status": 400}
Author
Owner

@xs818818 commented on GitHub (Nov 13, 2024):

and i want to use workflows

@xs818818 commented on GitHub (Nov 13, 2024): and i want to use workflows
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6747