summaryrefslogtreecommitdiff
path: root/matweb
diff options
context:
space:
mode:
authorjfriedli2025-01-12 12:11:06 +0000
committerjfriedli2025-01-12 12:11:06 +0000
commit1035a24707276a97c75a6fd1ecf9f425fb01fc10 (patch)
tree5543133f4c6b8d15fb438e244a21091450fa5822 /matweb
parenta5715f9f8cecaa74a5f5f385b63631d15102567c (diff)
Added Non-Ascii filename support
Diffstat (limited to 'matweb')
-rw-r--r--matweb/frontend.py2
-rw-r--r--matweb/utils.py13
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
2import os 2import os
3import hashlib 3import hashlib
4import mimetypes as mtype 4import mimetypes as mtype
5import pathlib
6import uuid
5from typing import Tuple 7from typing import Tuple
6 8
7from flask_restful import abort, current_app 9from flask_restful import abort, current_app
@@ -68,9 +70,16 @@ def get_supported_extensions():
68 70
69 71
70def save_file(file, upload_folder): 72def 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