Files uploaded to API not recognized by Dify #10805

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

Originally created by @lema-founders on GitHub (Mar 13, 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.3

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

  1. Use files (multiple), file (singular) and / just sys.files for documents, video, and / image (they all don't work)
    Image
  2. Use this code to create the API call
const handleFileSelect = async (e: React.ChangeEvent<HTMLInputElement>) => {
    if (!e.target.files || !activeChatId) return;

    setIsUploading(true);

    // Convert FileList to an array and process each file
    const files = Array.from(e.target.files);
    const newFiles: ChatFile[] = [];

    for (const file of files) {
      const formData = new FormData();
      // Append the file with its MIME type
      formData.append('file', file, file.name); // This will automatically set the correct MIME type
      formData.append('user', userId);

      try {
        const response = await fetch(`${DIFY_API_URL}/files/upload`, {
          method: 'POST',
          headers: {
            'Authorization': `Bearer ${DIFY_API_KEY}`
            // Note: Do not set Content-Type here; the browser will set the correct multipart boundary.
          },
          body: formData
        });

        if (!response.ok) {
          console.error("File upload error:", response.statusText);
          continue;
        }

        // Parse the JSON response from Dify
        const fileData = await response.json();

        // Create a ChatFile object including the additional fields from Dify's response.
        newFiles.push({
          id: fileData.id,
          name: fileData.name,
          type: fileData.mime_type,
          extension: fileData.extension, // New field per API response
          size: fileData.size,
          url: `${DIFY_API_URL}/files/${fileData.id}`,
          created_at: fileData.created_at,
          created_by: fileData.created_by  // New field per API response
        });

        console.log("File uploaded successfully:", fileData);
      } catch (error) {
        console.error("Error uploading file:", error);
      }
    }

    setSelectedFiles([...selectedFiles, ...newFiles]);
    setIsUploading(false);
  1. Send a message with uploaded file / files and create API call based on code above

✔️ Expected Behavior

Dify recognizing the image and showing it in logs

Actual Behavior

Currently it doesn't recognize the file and uploaded files also don't show up on logs despite showing in console and sent to the API

Image

Image

Originally created by @lema-founders on GitHub (Mar 13, 2025). ### 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.15.3 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce 1. Use files (multiple), file (singular) and / just sys.files for documents, video, and / image (they all don't work) ![Image](https://github.com/user-attachments/assets/52824ee5-c993-4f13-8748-3e1b3367279d) 2. Use this code to create the API call ``` const handleFileSelect = async (e: React.ChangeEvent<HTMLInputElement>) => { if (!e.target.files || !activeChatId) return; setIsUploading(true); // Convert FileList to an array and process each file const files = Array.from(e.target.files); const newFiles: ChatFile[] = []; for (const file of files) { const formData = new FormData(); // Append the file with its MIME type formData.append('file', file, file.name); // This will automatically set the correct MIME type formData.append('user', userId); try { const response = await fetch(`${DIFY_API_URL}/files/upload`, { method: 'POST', headers: { 'Authorization': `Bearer ${DIFY_API_KEY}` // Note: Do not set Content-Type here; the browser will set the correct multipart boundary. }, body: formData }); if (!response.ok) { console.error("File upload error:", response.statusText); continue; } // Parse the JSON response from Dify const fileData = await response.json(); // Create a ChatFile object including the additional fields from Dify's response. newFiles.push({ id: fileData.id, name: fileData.name, type: fileData.mime_type, extension: fileData.extension, // New field per API response size: fileData.size, url: `${DIFY_API_URL}/files/${fileData.id}`, created_at: fileData.created_at, created_by: fileData.created_by // New field per API response }); console.log("File uploaded successfully:", fileData); } catch (error) { console.error("Error uploading file:", error); } } setSelectedFiles([...selectedFiles, ...newFiles]); setIsUploading(false); ``` 3. Send a message with uploaded file / files and create API call based on code above ### ✔️ Expected Behavior Dify recognizing the image and showing it in logs ### ❌ Actual Behavior Currently it doesn't recognize the file and uploaded files also don't show up on logs despite showing in console and sent to the API ![Image](https://github.com/user-attachments/assets/62f096d6-9191-4875-9261-9cbd9c62c25e) ![Image](https://github.com/user-attachments/assets/0889100c-7ab4-4c36-a38f-c2d0a1b2fb5a)
yindo added the 🤔 cant-reproduce label 2026-02-21 18:51:24 -05:00
yindo closed this issue 2026-02-21 18:51:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#10805