🐛 fix(utils.py): handle cases where file.filename is not a string or Path object to prevent errors

🔧 chore(utils.py): refactor save_uploaded_file function to improve code readability and maintainability
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-09-26 11:13:48 -03:00
commit 12a5dd8fde

View file

@ -169,7 +169,11 @@ def save_uploaded_file(file: UploadFile, folder_name):
"""
cache_path = Path(CACHE_DIR)
folder_path = cache_path / folder_name
file_extension = Path(file.filename).suffix
filename = file.filename
if isinstance(filename, str) or isinstance(filename, Path):
file_extension = Path(filename).suffix
else:
file_extension = ""
file_object = file.file
# Create the folder if it doesn't exist