mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-04 02:33:43 +00:00
fix form for upload file handler
When upload_file_handler is called directly (not via HTTP), Form(None) doesn't resolve to None - it remains a Form object.
This commit is contained in:
parent
4c581349bd
commit
1cfd0fb1ae
1 changed files with 10 additions and 3 deletions
|
|
@ -194,15 +194,22 @@ async def upload_file_handler(
|
|||
):
|
||||
log.info(f'file.content_type: {file.content_type} {process}')
|
||||
|
||||
if isinstance(metadata, str):
|
||||
# Handle metadata: when called directly (not via HTTP), Form(None) remains a Form object
|
||||
# When called via HTTP, FastAPI resolves it to None or the actual value
|
||||
if metadata is None or (hasattr(metadata, '__class__') and metadata.__class__.__name__ == 'Form'):
|
||||
file_metadata = {}
|
||||
elif isinstance(metadata, str):
|
||||
try:
|
||||
metadata = json.loads(metadata)
|
||||
file_metadata = json.loads(metadata)
|
||||
except json.JSONDecodeError:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=ERROR_MESSAGES.DEFAULT('Invalid metadata format'),
|
||||
)
|
||||
file_metadata = metadata if metadata else {}
|
||||
elif isinstance(metadata, dict):
|
||||
file_metadata = metadata
|
||||
else:
|
||||
file_metadata = {}
|
||||
|
||||
try:
|
||||
unsanitized_filename = file.filename
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue