diff options
| author | jfriedli | 2025-01-12 12:11:06 +0000 |
|---|---|---|
| committer | jfriedli | 2025-01-12 12:11:06 +0000 |
| commit | 1035a24707276a97c75a6fd1ecf9f425fb01fc10 (patch) | |
| tree | 5543133f4c6b8d15fb438e244a21091450fa5822 /matweb/utils.py | |
| parent | a5715f9f8cecaa74a5f5f385b63631d15102567c (diff) | |
Added Non-Ascii filename support
Diffstat (limited to '')
| -rw-r--r-- | matweb/utils.py | 13 |
1 files changed, 11 insertions, 2 deletions
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 | |||
| 2 | import os | 2 | import os |
| 3 | import hashlib | 3 | import hashlib |
| 4 | import mimetypes as mtype | 4 | import mimetypes as mtype |
| 5 | import pathlib | ||
| 6 | import uuid | ||
| 5 | from typing import Tuple | 7 | from typing import Tuple |
| 6 | 8 | ||
| 7 | from flask_restful import abort, current_app | 9 | from flask_restful import abort, current_app |
| @@ -68,9 +70,16 @@ def get_supported_extensions(): | |||
| 68 | 70 | ||
| 69 | 71 | ||
| 70 | def save_file(file, upload_folder): | 72 | def save_file(file, upload_folder): |
| 71 | filename = secure_filename(file.filename) | 73 | path = pathlib.Path(file.filename) |
| 74 | extension = path.suffix | ||
| 75 | stem = path.stem | ||
| 76 | |||
| 77 | filename = secure_filename(stem) | ||
| 72 | if not filename: | 78 | if not filename: |
| 73 | raise ValueError('Invalid Filename') | 79 | filename = str(uuid.uuid4()) |
| 80 | |||
| 81 | if extension: | ||
| 82 | filename = str(pathlib.Path(filename).with_suffix(extension)) | ||
| 74 | filepath = os.path.join(upload_folder, filename) | 83 | filepath = os.path.join(upload_folder, filename) |
| 75 | file.save(os.path.join(filepath)) | 84 | file.save(os.path.join(filepath)) |
| 76 | return filename, filepath | 85 | return filename, filepath |
