diff options
Diffstat (limited to 'matweb')
| -rw-r--r-- | matweb/frontend.py | 2 | ||||
| -rw-r--r-- | matweb/utils.py | 13 |
2 files changed, 12 insertions, 3 deletions
diff --git a/matweb/frontend.py b/matweb/frontend.py index 018fc97..ec9ef23 100644 --- a/matweb/frontend.py +++ b/matweb/frontend.py | |||
| @@ -68,7 +68,7 @@ def upload_file(): | |||
| 68 | parser, mime = utils.get_file_parser(filepath) | 68 | parser, mime = utils.get_file_parser(filepath) |
| 69 | except ValueError: | 69 | except ValueError: |
| 70 | flash('The filetype is not supported') | 70 | flash('The filetype is not supported') |
| 71 | current_app.logger.error('Unsupported filetype',) | 71 | current_app.logger.error('Unsupported filetype') |
| 72 | return redirect(url_for('routes.upload_file')) | 72 | return redirect(url_for('routes.upload_file')) |
| 73 | 73 | ||
| 74 | try: | 74 | try: |
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 |
