refac
This commit is contained in:
1 parent
fd7a59d37a
commit
f8ec63203c
1 file changed
+13
-2
@@ -338,11 +338,22 @@ async def upload_file_handler(
|
|||||||
contents, file_path = await asyncio.to_thread(Storage.upload_file, file.file, filename, tags)
|
contents, file_path = await asyncio.to_thread(Storage.upload_file, file.file, filename, tags)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.ENAMETOOLONG:
|
if e.errno != errno.ENAMETOOLONG:
|
||||||
raise
|
log.exception(e)
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
detail=ERROR_MESSAGES.DEFAULT(e.strerror or 'Error uploading file'),
|
||||||
|
)
|
||||||
|
|
||||||
file.file.seek(0)
|
file.file.seek(0)
|
||||||
filename = f'{id}.{file_extension}' if file_extension else id
|
filename = f'{id}.{file_extension}' if file_extension else id
|
||||||
contents, file_path = await asyncio.to_thread(Storage.upload_file, file.file, filename, tags)
|
try:
|
||||||
|
contents, file_path = await asyncio.to_thread(Storage.upload_file, file.file, filename, tags)
|
||||||
|
except OSError as e:
|
||||||
|
log.exception(e)
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
detail=ERROR_MESSAGES.DEFAULT(e.strerror or 'Error uploading file'),
|
||||||
|
)
|
||||||
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)
|
||||||
|
|||||||
Reference in new issue
Block a user