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

Fix Custom Tool File Upload: Resolve Multiple Files Recognition and Multipart Boundary Issues #14014

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

JimHeo
Copy link

@JimHeo JimHeo commented Feb 19, 2025

Summary

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Tip

Close issue syntax: Fixes #<issue number> or Resolves #<issue number>, see documentation for more details.

  1. cannot multiple files upload: Files variable in Custom tool cannot be recognized correctlly #11255 (comment)
  2. missing boundary in multipart error: The custom tool for multipart/form-data requests encountered a 'Missing boundary in multipart' error #13684

Screenshots

Before
스크린샷 2025-02-19 오후 4 04 38

After
스크린샷 2025-02-19 오후 4 03 40

Checklist

Important

Please review the checklist below before submitting your pull request.

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. 🔨 feat:tools Tools for agent, function call related stuff. labels Feb 19, 2025
@JimHeo JimHeo changed the title Fix/custom tool Fix/custom tool: upload multiple files Feb 19, 2025
@JimHeo
Copy link
Author

JimHeo commented Feb 21, 2025

Hi, Just a friendly reminder regarding my PR that addresses the following issues:

  1. cannot multiple files upload: Files variable in Custom tool cannot be recognized correctlly #11255 (comment)
  • When adding the multiple file upload feature in the custom tool, the input is mistakenly interpreted as a String rather than an Array[File], causing the files not to be received. For example, consider this FastAPI snippet:
@app.post("/upload-images/")
async def upload_images(files: List[UploadFile] = File(...)):
    if not files:
        raise HTTPException(status_code=400, detail="No files uploaded.")
        
    for file in files:
        if not file.content_type.startswith("image/"):
            return {"success": False}
        await file.read()
        
    return {"success": True}
  1. missing boundary in multipart error: The custom tool for multipart/form-data requests encountered a 'Missing boundary in multipart' error #13684
  • To support both multi-file and single-file uploads, the multipart/form-data schema needs to include the appropriate boundary. This PR addresses the issue to prevent users from having to manually modify the header to something like multipart/form-data; boundary=----WebKitFormBoundarydzemBAPhdeDfTCfR, ensuring a more robust and error-free implementation.

I’d appreciate it if you could review the changes at your earliest convenience. Thanks for your time!
@crazywoola @iamjoel @Nov1c444

@JimHeo JimHeo changed the title Fix/custom tool: upload multiple files Fix Custom Tool File Upload: Resolve Multiple Files Recognition and Multipart Boundary Issues Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 feat:tools Tools for agent, function call related stuff. size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant