mirror of
https://0xacab.org/jvoisin/mat2-web.git
synced 2025-08-02 11:16:14 -04:00
Added Non-Ascii filename support
This commit is contained in:
parent
a5715f9f8c
commit
1035a24707
4 changed files with 30 additions and 10 deletions
|
@ -68,7 +68,7 @@ def upload_file():
|
|||
parser, mime = utils.get_file_parser(filepath)
|
||||
except ValueError:
|
||||
flash('The filetype is not supported')
|
||||
current_app.logger.error('Unsupported filetype',)
|
||||
current_app.logger.error('Unsupported filetype')
|
||||
return redirect(url_for('routes.upload_file'))
|
||||
|
||||
try:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue