This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-29 04:27:48 -05:00
1 parent ea6d02da0f
commit fd7a59d37a
1 file changed
+17 -12
+17 -12
View File
@@ -1,4 +1,5 @@
import asyncio import asyncio
import errno
import hashlib import hashlib
import json import json
import logging import logging
@@ -323,21 +324,25 @@ async def upload_file_handler(
detail=ERROR_MESSAGES.DEFAULT(f'File type {file_extension} is not allowed'), detail=ERROR_MESSAGES.DEFAULT(f'File type {file_extension} is not allowed'),
) )
# replace filename with uuid # Prefer readable storage names for admins, but fall back if the filesystem rejects it.
id = str(uuid.uuid4()) id = str(uuid.uuid4())
name = filename name = filename
filename = f'{id}_{filename}' filename = f'{id}_{filename}'
contents, file_path = await asyncio.to_thread( tags = {
Storage.upload_file, 'OpenWebUI-User-Email': user.email,
file.file, 'OpenWebUI-User-Id': user.id,
filename, 'OpenWebUI-User-Name': user.name,
{ 'OpenWebUI-File-Id': id,
'OpenWebUI-User-Email': user.email, }
'OpenWebUI-User-Id': user.id, try:
'OpenWebUI-User-Name': user.name, contents, file_path = await asyncio.to_thread(Storage.upload_file, file.file, filename, tags)
'OpenWebUI-File-Id': id, except OSError as e:
}, if e.errno != errno.ENAMETOOLONG:
) raise
file.file.seek(0)
filename = f'{id}.{file_extension}' if file_extension else id
contents, file_path = await asyncio.to_thread(Storage.upload_file, file.file, filename, tags)
max_size = await Config.get('rag.file.max_size') max_size = await Config.get('rag.file.max_size')
if max_size and len(contents) > int(max_size) * 1024 * 1024: if max_size and len(contents) > int(max_size) * 1024 * 1024:
await asyncio.to_thread(Storage.delete_file, file_path) await asyncio.to_thread(Storage.delete_file, file_path)