guess mimetype if extension not provided on upload
This commit is contained in:
parent
6dcf787c4f
commit
77926ec92b
|
@ -7,6 +7,7 @@ import giteapy
|
||||||
import giteapy.rest
|
import giteapy.rest
|
||||||
import time
|
import time
|
||||||
import base64
|
import base64
|
||||||
|
import mimetypes
|
||||||
|
|
||||||
|
|
||||||
from werkzeug.datastructures import FileStorage
|
from werkzeug.datastructures import FileStorage
|
||||||
|
@ -143,8 +144,13 @@ def process_photo_upload(created_at: datetime, file: FileStorage, suffix: str=""
|
||||||
|
|
||||||
if os.environ.get('MICROPUB_IMAGE_STRATEGY') == 'copy':
|
if os.environ.get('MICROPUB_IMAGE_STRATEGY') == 'copy':
|
||||||
|
|
||||||
|
file.mimetype
|
||||||
|
|
||||||
ext = os.path.splitext(file.filename)[1]
|
ext = os.path.splitext(file.filename)[1]
|
||||||
|
|
||||||
|
if ext == "":
|
||||||
|
ext = mimetypes.guess_extension(file.mimetype)
|
||||||
|
|
||||||
# generate local filename
|
# generate local filename
|
||||||
filename = os.path.join(os.environ.get(
|
filename = os.path.join(os.environ.get(
|
||||||
'MICROPUB_MEDIA_PATH'), created_at.strftime("%Y/%m/%d"), f"{now_ts}_{suffix}{ext}")
|
'MICROPUB_MEDIA_PATH'), created_at.strftime("%Y/%m/%d"), f"{now_ts}_{suffix}{ext}")
|
||||||
|
|
Loading…
Reference in New Issue