diff options
Diffstat (limited to 'matweb/utils.py')
| -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 |
