From 1035a24707276a97c75a6fd1ecf9f425fb01fc10 Mon Sep 17 00:00:00 2001 From: jfriedli Date: Sun, 12 Jan 2025 12:11:06 +0000 Subject: Added Non-Ascii filename support --- matweb/utils.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'matweb/utils.py') diff --git a/matweb/utils.py b/matweb/utils.py index 270c5f3..39159e1 100644 --- a/matweb/utils.py +++ b/matweb/utils.py @@ -2,6 +2,8 @@ import hmac import os import hashlib import mimetypes as mtype +import pathlib +import uuid from typing import Tuple from flask_restful import abort, current_app @@ -68,9 +70,16 @@ def get_supported_extensions(): def save_file(file, upload_folder): - filename = secure_filename(file.filename) + path = pathlib.Path(file.filename) + extension = path.suffix + stem = path.stem + + filename = secure_filename(stem) if not filename: - raise ValueError('Invalid Filename') + filename = str(uuid.uuid4()) + + if extension: + filename = str(pathlib.Path(filename).with_suffix(extension)) filepath = os.path.join(upload_folder, filename) file.save(os.path.join(filepath)) return filename, filepath -- cgit v1.3