mirror of
https://0xacab.org/jvoisin/mat2-web.git
synced 2025-05-12 19:22:21 -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
|
@ -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