Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file id is null #13159

Closed
5 tasks done
HuChundong opened this issue Feb 2, 2025 · 5 comments · Fixed by #13175
Closed
5 tasks done

file id is null #13159

HuChundong opened this issue Feb 2, 2025 · 5 comments · Fixed by #13175
Assignees

Comments

@HuChundong
Copy link
Contributor

HuChundong commented Feb 2, 2025

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.15.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

a min dsl to show this issue:

app:
  description: ''
  icon: 🤖
  icon_background: '#FFEAD5'
  mode: advanced-chat
  name: test
  use_icon_as_answer_icon: false
kind: app
version: 0.1.5
workflow:
  conversation_variables: []
  environment_variables: []
  features:
    file_upload:
      allowed_file_extensions:
      - .JPG
      - .JPEG
      - .PNG
      - .GIF
      - .WEBP
      - .SVG
      allowed_file_types:
      - image
      allowed_file_upload_methods:
      - local_file
      - remote_url
      enabled: false
      fileUploadConfig:
        audio_file_size_limit: 50
        batch_count_limit: 5
        file_size_limit: 15
        image_file_size_limit: 10
        video_file_size_limit: 100
        workflow_file_upload_limit: 10
      image:
        enabled: false
        number_limits: 3
        transfer_methods:
        - local_file
        - remote_url
      number_limits: 3
    opening_statement: ''
    retriever_resource:
      enabled: true
    sensitive_word_avoidance:
      enabled: false
    speech_to_text:
      enabled: false
    suggested_questions: []
    suggested_questions_after_answer:
      enabled: false
    text_to_speech:
      enabled: false
      language: ''
      voice: ''
  graph:
    edges:
    - data:
        isInIteration: false
        sourceType: start
        targetType: tool
      id: 1738532363024-source-1738532389502-target
      source: '1738532363024'
      sourceHandle: source
      target: '1738532389502'
      targetHandle: target
      type: custom
      zIndex: 0
    - data:
        isInIteration: false
        sourceType: tool
        targetType: answer
      id: 1738532389502-source-answer-target
      source: '1738532389502'
      sourceHandle: source
      target: answer
      targetHandle: target
      type: custom
      zIndex: 0
    nodes:
    - data:
        desc: ''
        selected: false
        title: 开始
        type: start
        variables:
        - allowed_file_extensions: []
          allowed_file_types:
          - image
          - document
          - audio
          - video
          allowed_file_upload_methods:
          - local_file
          - remote_url
          label: user_file
          max_length: 48
          options: []
          required: false
          type: file
          variable: user_file
      height: 89
      id: '1738532363024'
      position:
        x: 80
        y: 282
      positionAbsolute:
        x: 80
        y: 282
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 243
    - data:
        answer: '{{#1738532389502.text#}}'
        desc: ''
        selected: false
        title: 直接回复
        type: answer
        variables: []
      height: 102
      id: answer
      position:
        x: 763.1289983786921
        y: 272.76344462458974
      positionAbsolute:
        x: 763.1289983786921
        y: 272.76344462458974
      selected: true
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 243
    - data:
        desc: ''
        provider_id: 6192c406-fe54-40ce-973a-50b568301c2c
        provider_name: 封装返回结构
        provider_type: workflow
        selected: false
        title: 封装返回结构
        tool_configurations: {}
        tool_label: 封装返回结构
        tool_name: pack_response
        tool_parameters:
          files:
            type: variable
            value:
            - '1738532363024'
            - user_file
          response:
            type: mixed
            value: test
          status:
            type: constant
            value: 0
        type: tool
      height: 53
      id: '1738532389502'
      position:
        x: 422.99307122794414
        y: 296.1918580055515
      positionAbsolute:
        x: 422.99307122794414
        y: 296.1918580055515
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 243
    viewport:
      x: 60.35141579483934
      y: 222.44530247148222
      zoom: 0.7578582832551992

✔️ Expected Behavior

when i upload file, the id is null, but when i use this file as param, error report: Run failed: Failed to invoke tool: Invalid upload file id
web and api both report this issue.

{
"user_file": {
"dify_model_identity": "dify__file",
"id": null,
"tenant_id": "c6165e3a-fb17-48cb-aa03-fc0db568fd71",
"type": "document",
"transfer_method": "local_file",
"remote_url": "",
"related_id": "f03a14aa-0986-424a-8112-c12ec162872f",
"filename": "api-doc.txt",
"extension": ".txt",
"mime_type": "text/plain",
"size": 18081,
"url": "/files/f03a14aa-0986-424a-8112-c12ec162872f/file-preview?timestamp=1738532135&nonce=464b7957014d5649ee113ed8bdd61c1a&sign=Y2rUMWbi9AYIHw1rKw8zT_Fv0FY9A7RmlUHRMTOhh3s="
},
"sys.query": "dd",
"sys.files": [],
"sys.conversation_id": "e0258f20-7541-4fea-9526-48f72c2b548e",
"sys.user_id": "7743e2d7-cf48-426e-9a4a-05c58b289e03",
"sys.dialogue_count": 0,
"sys.app_id": "88910469-0772-4ec6-b742-93de4e0196b7",
"sys.workflow_id": "4aba5c71-4706-42de-81a8-902cb84ccccc",
"sys.workflow_run_id": "b25ca1a2-144c-4def-a04c-cf8f1e2ddc02"
}

❌ Actual Behavior

No response

@dosubot dosubot bot added the 🐞 bug Something isn't working label Feb 2, 2025
Copy link

dosubot bot commented Feb 2, 2025

Hello, @HuChundong! I'm here to help you with any bugs, questions, or contributions you have in mind. Let's tackle this issue together!

A file ID being null after an upload attempt in the Dify platform can occur due to several reasons. Here are some potential causes and checks you can perform:

  1. File Upload Configuration: Ensure that the file upload feature is enabled in your workflow configuration. In your provided configuration, file_upload is set to enabled: false. This needs to be set to true to allow file uploads.

  2. Allowed File Types and Extensions: Verify that the file type and extension you are trying to upload are included in the allowed_file_types and allowed_file_extensions lists. Your configuration allows image types, but the uploaded file is a document (.txt), which might not be permitted.

  3. File Size and Limits: Check if the file size exceeds the configured limits. The file_size_limit is set to 15MB, so ensure the file is within this limit.

  4. User Permissions: Ensure that the user has the necessary permissions to upload files, especially if the source is "datasets".

  5. Error Handling and Logging: Check the logs for any error messages related to the file upload process. This can provide more insight into why the file ID is null.

  6. File Presence and Count: Ensure that exactly one file is being uploaded. If no file is uploaded or more than one file is uploaded, it could result in a null ID.

By addressing these areas, you should be able to identify the cause of the null file ID and resolve the issue.

To continue talking to Dosu, mention @dosu.


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

@HuChundong
Copy link
Contributor Author

i have change my chatflow. but it not help. because the file id is still null.

app:
  description: ''
  icon: 🤖
  icon_background: '#FFEAD5'
  mode: advanced-chat
  name: test
  use_icon_as_answer_icon: false
kind: app
version: 0.1.5
workflow:
  conversation_variables: []
  environment_variables: []
  features:
    file_upload:
      allowed_file_extensions:
      - .txt
      allowed_file_types:
      - video
      - audio
      - image
      - document
      allowed_file_upload_methods:
      - remote_url
      - local_file
      enabled: true
      fileUploadConfig:
        audio_file_size_limit: 50
        batch_count_limit: 5
        file_size_limit: 15
        image_file_size_limit: 10
        video_file_size_limit: 100
        workflow_file_upload_limit: 10
      image:
        enabled: false
        number_limits: 3
        transfer_methods:
        - local_file
        - remote_url
      number_limits: 1
    opening_statement: ''
    retriever_resource:
      enabled: true
    sensitive_word_avoidance:
      enabled: false
    speech_to_text:
      enabled: false
    suggested_questions: []
    suggested_questions_after_answer:
      enabled: false
    text_to_speech:
      enabled: false
      language: ''
      voice: ''
  graph:
    edges:
    - data:
        isInIteration: false
        sourceType: start
        targetType: tool
      id: 1738532363024-source-1738532389502-target
      source: '1738532363024'
      sourceHandle: source
      target: '1738532389502'
      targetHandle: target
      type: custom
      zIndex: 0
    - data:
        isInIteration: false
        sourceType: tool
        targetType: answer
      id: 1738532389502-source-answer-target
      source: '1738532389502'
      sourceHandle: source
      target: answer
      targetHandle: target
      type: custom
      zIndex: 0
    nodes:
    - data:
        desc: ''
        selected: true
        title: 开始
        type: start
        variables:
        - allowed_file_extensions: []
          allowed_file_types:
          - image
          - document
          - audio
          - video
          allowed_file_upload_methods:
          - local_file
          - remote_url
          label: user_file
          max_length: 48
          options: []
          required: false
          type: file
          variable: user_file
      height: 89
      id: '1738532363024'
      position:
        x: 80
        y: 280.6804920892271
      positionAbsolute:
        x: 80
        y: 280.6804920892271
      selected: true
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 243
    - data:
        answer: '{{#1738532389502.text#}}'
        desc: ''
        selected: false
        title: 直接回复
        type: answer
        variables: []
      height: 102
      id: answer
      position:
        x: 763.1289983786921
        y: 272.76344462458974
      positionAbsolute:
        x: 763.1289983786921
        y: 272.76344462458974
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 243
    - data:
        desc: ''
        provider_id: 6192c406-fe54-40ce-973a-50b568301c2c
        provider_name: 封装返回结构
        provider_type: workflow
        selected: false
        title: 封装返回结构
        tool_configurations: {}
        tool_label: 封装返回结构
        tool_name: pack_response
        tool_parameters:
          files:
            type: variable
            value:
            - '1738532363024'
            - user_file
          response:
            type: mixed
            value: test
          status:
            type: constant
            value: 0
        type: tool
      height: 53
      id: '1738532389502'
      position:
        x: 422.99307122794414
        y: 296.1918580055515
      positionAbsolute:
        x: 422.99307122794414
        y: 296.1918580055515
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 243
    viewport:
      x: 191.99125013167668
      y: 186.08042124219423
      zoom: 0.870550563296124

`

@crazywoola crazywoola removed the 🐞 bug Something isn't working label Feb 3, 2025
@crazywoola
Copy link
Member

If you want to to get file id, please use the related_id instead.

if file.transfer_method == FileTransferMethod.TOOL_FILE:
file_dict["tool_file_id"] = file.related_id
elif file.transfer_method == FileTransferMethod.LOCAL_FILE:
file_dict["upload_file_id"] = file.related_id
elif file.transfer_method == FileTransferMethod.REMOTE_URL:
file_dict["url"] = file.generate_url()

@HuChundong
Copy link
Contributor Author

The issue is not the absence of a file id, but rather the missing file id, which will cause errors in next nodes that use the file. You can use the DSL above for testing.

@HuChundong
Copy link
Contributor Author

NEED REOPEN ISSUE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment