[GH-ISSUE #10342] bug: Including file_metadata in /files/ route not working #54527

Closed
opened 2026-05-05 16:22:20 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @almajo on GitHub (Feb 19, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/10342

Bug Report

Environment

  • Open WebUI Version: 0.5.14

Confirmation:

  • [ X ] I have read and followed all the instructions provided in the README.md.
  • [ X ] I am on the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below.

Expected Behavior:

Since one of the last versions, 'file_metadata' was added to the /files POST route when uploading files. When adding a dictionary, I want this to be added within meta of the file.

Actual Behavior:

When calling the API (even through the Swagger UI), the API returns a 422 Error: Uprocessable Entity

Description

Bug Summary:

Either through python requests or CURL, I can't get it working.

Through the UI I send the following request:

curl -X 'POST' \
  'http://localhost:3000/api/v1/files/' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -F 'file=@a357116e-9ddd-4f72-86dd-2d855be398a3 Kopie.pdf;type=application/pdf' \
  -F 'file_metadata="{
    "test": "test1, test2, test3",
}"'

and receive this response:

{
  "detail": [
    {
      "type": "dict_type",
      "loc": [
        "body",
        "file_metadata"
      ],
      "msg": "Input should be a valid dictionary",
      "input": "\"{\r\n    \"test\": \"test1, test2, test3\",\r\n}\""
    }
  ]
}

with headers

 access-control-allow-credentials: true 
 access-control-allow-origin: http://localhost:3000 
 content-length: 170 
 content-type: application/json 
 date: Wed,19 Feb 2025 09:00:41 GMT 
 server: uvicorn 
 vary: Origin 
 x-process-time: 0 

I also played around sending the request through request where I tried adding the metadata to json or data argument. Same results.

Sending no metadata works to upload the file

Reproduction Details

Steps to Reproduce:

Super simple. Open Swagger UI on /docs and send a POST request to /api/v1/files/ with an uploaded file and include metadata.

Originally created by @almajo on GitHub (Feb 19, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/10342 # Bug Report ## Environment - **Open WebUI Version:** 0.5.14 **Confirmation:** - [ X ] I have read and followed all the instructions provided in the README.md. - [ X ] I am on the latest version of both Open WebUI and Ollama. - [ ] I have included the browser console logs. - [ ] I have included the Docker container logs. - [ ] I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below. ## Expected Behavior: Since one of the last versions, 'file_metadata' was added to the /files POST route when uploading files. When adding a dictionary, I want this to be added within `meta` of the file. ## Actual Behavior: When calling the API (even through the Swagger UI), the API returns a 422 Error: Uprocessable Entity ## Description **Bug Summary:** Either through python requests or CURL, I can't get it working. Through the UI I send the following request: ```bash curl -X 'POST' \ 'http://localhost:3000/api/v1/files/' \ -H 'accept: application/json' \ -H 'Content-Type: multipart/form-data' \ -F 'file=@a357116e-9ddd-4f72-86dd-2d855be398a3 Kopie.pdf;type=application/pdf' \ -F 'file_metadata="{ "test": "test1, test2, test3", }"' ``` and receive this response: ```json { "detail": [ { "type": "dict_type", "loc": [ "body", "file_metadata" ], "msg": "Input should be a valid dictionary", "input": "\"{\r\n \"test\": \"test1, test2, test3\",\r\n}\"" } ] } ``` with headers ```yaml access-control-allow-credentials: true access-control-allow-origin: http://localhost:3000 content-length: 170 content-type: application/json date: Wed,19 Feb 2025 09:00:41 GMT server: uvicorn vary: Origin x-process-time: 0 ``` I also played around sending the request through request where I tried adding the metadata to json or data argument. Same results. Sending no metadata works to upload the file ## Reproduction Details **Steps to Reproduce:** Super simple. Open Swagger UI on <webui>/docs and send a POST request to /api/v1/files/ with an uploaded file and include metadata.
Author
Owner

@tjbck commented on GitHub (Feb 19, 2025):

file_metadata is not intended to be accessible by API.

<!-- gh-comment-id:2668095811 --> @tjbck commented on GitHub (Feb 19, 2025): `file_metadata` is not intended to be accessible by API.
Author
Owner

@almajo commented on GitHub (Feb 19, 2025):

Hi @tjbck, why not?

When adding a file through an external script,I would like to have some metadata (custom urls, titles, user restrictions, ...) in order to use this later for knowledge retrieval and citations. That would be a great benefit.

Even if it's not intended, do you know a way how to use it anyway through API?

<!-- gh-comment-id:2668229783 --> @almajo commented on GitHub (Feb 19, 2025): Hi @tjbck, why not? When adding a file through an external script,I would like to have some metadata (custom urls, titles, user restrictions, ...) in order to use this later for knowledge retrieval and citations. That would be a great benefit. Even if it's not intended, do you know a way how to use it anyway through API?
Author
Owner

@kaytwo commented on GitHub (Mar 24, 2025):

I just ran into this as well - same need, pity it won't be supported. My read of how b03fc97e28/backend/open_webui/routers/files.py (L36) works is that there's no way to successfully upload file_metadata as is, I can't seem to get the pydantic model to validate the input dictionary, it would probably need a fix like https://stackoverflow.com/questions/63110848/how-do-i-send-list-of-dictionary-as-body-parameter-together-with-files-in-fastap to work properly.

For what it's worth, my workaround is to put whatever metadata is relevant in the body of the file itself, as there isn't currently any performance gain to be had by accessing just metadata vs. all of the file's data all at once (the api only ever gives you the metadata+data afaict).

<!-- gh-comment-id:2749494574 --> @kaytwo commented on GitHub (Mar 24, 2025): I just ran into this as well - same need, pity it won't be supported. My read of how https://github.com/open-webui/open-webui/blob/b03fc97e287f31ad07bda896143959bc4413f7d2/backend/open_webui/routers/files.py#L36 works is that there's no way to successfully upload file_metadata as is, I can't seem to get the pydantic model to validate the input dictionary, it would probably need a fix like https://stackoverflow.com/questions/63110848/how-do-i-send-list-of-dictionary-as-body-parameter-together-with-files-in-fastap to work properly. For what it's worth, my workaround is to put whatever metadata is relevant in the body of the file itself, as there isn't currently any performance gain to be had by accessing just metadata vs. all of the file's data all at once (the api only ever gives you the metadata+data afaict).
Author
Owner

@HyuPete commented on GitHub (May 7, 2025):

I just ran into this as well - same need, pity it won't be supported. My read of how

open-webui/backend/open_webui/routers/files.py

Line 36 in b03fc97

def upload_file(
works is that there's no way to successfully upload file_metadata as is, I can't seem to get the pydantic model to validate the input dictionary, it would probably need a fix like https://stackoverflow.com/questions/63110848/how-do-i-send-list-of-dictionary-as-body-parameter-together-with-files-in-fastap to work properly.
For what it's worth, my workaround is to put whatever metadata is relevant in the body of the file itself, as there isn't currently any performance gain to be had by accessing just metadata vs. all of the file's data all at once (the api only ever gives you the metadata+data afaict).

Image

My workaround is to make some small changes to backend/open_webui/routers/files.py like in the attached image. Comments are welcome.

<!-- gh-comment-id:2857383334 --> @HyuPete commented on GitHub (May 7, 2025): > I just ran into this as well - same need, pity it won't be supported. My read of how > > [open-webui/backend/open_webui/routers/files.py](https://github.com/open-webui/open-webui/blob/b03fc97e287f31ad07bda896143959bc4413f7d2/backend/open_webui/routers/files.py#L36) > > Line 36 in [b03fc97](/open-webui/open-webui/commit/b03fc97e287f31ad07bda896143959bc4413f7d2) > > def upload_file( > works is that there's no way to successfully upload file_metadata as is, I can't seem to get the pydantic model to validate the input dictionary, it would probably need a fix like https://stackoverflow.com/questions/63110848/how-do-i-send-list-of-dictionary-as-body-parameter-together-with-files-in-fastap to work properly. > For what it's worth, my workaround is to put whatever metadata is relevant in the body of the file itself, as there isn't currently any performance gain to be had by accessing just metadata vs. all of the file's data all at once (the api only ever gives you the metadata+data afaict). ![Image](https://github.com/user-attachments/assets/b1a792b6-dd1c-4d95-b072-28ab6ed7a4ca) My workaround is to make some small changes to `backend/open_webui/routers/files.py` like in the attached image. Comments are welcome.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#54527