guess mimetype if extension not provided on upload

This commit is contained in:
James Ravenscroft 2023-10-28 13:01:33 +01:00
parent 6dcf787c4f
commit 77926ec92b
1 changed files with 6 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import giteapy
import giteapy.rest
import time
import base64
import mimetypes
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':
file.mimetype
ext = os.path.splitext(file.filename)[1]
if ext == "":
ext = mimetypes.guess_extension(file.mimetype)
# generate local filename
filename = os.path.join(os.environ.get(
'MICROPUB_MEDIA_PATH'), created_at.strftime("%Y/%m/%d"), f"{now_ts}_{suffix}{ext}")