24
24
BadRequestException ,
25
25
ForbiddenException ,
26
26
NotFoundException ,
27
+ UnsupportedMediaException ,
27
28
)
28
29
from ayon_server .files import Storages
29
30
from ayon_server .helpers .mimetypes import guess_mime_type
@@ -84,8 +85,27 @@ async def store_thumbnail(
84
85
MAX_THUMBNAIL_WIDTH = 600
85
86
MAX_THUMBNAIL_HEIGHT = 600
86
87
87
- if guess_mime_type (payload ) != mime :
88
- raise BadRequestException ("Mime type does not match the payload" )
88
+ guessed_mime = guess_mime_type (payload )
89
+ if guessed_mime is None :
90
+ # This shouldn't happen, but we'll log it.
91
+ # Upload will probably fail later on, in process_thumbnail.
92
+ logging .warning (
93
+ f"Could not guess mime type of thumbnail. Using provided { mime } "
94
+ )
95
+
96
+ elif guessed_mime != mime :
97
+ # This is a warning, not an error, because we can still store the thumbnail
98
+ # even if the mime type is wrong. We're just logging it and using the
99
+ # correct mime type instead of the provided one.
100
+ logging .warning (
101
+ "Thumbnail mime type mismatch: "
102
+ f"Payload contains { guessed_mime } "
103
+ f"but was requested to store { mime } "
104
+ )
105
+ mime = guessed_mime
106
+
107
+ if mime not in ["image/png" , "image/jpeg" ]:
108
+ raise UnsupportedMediaException (f"Unsupported thumbnail mime type { mime } " )
89
109
90
110
try :
91
111
thumbnail = await process_thumbnail (
@@ -94,7 +114,8 @@ async def store_thumbnail(
94
114
raise_on_noop = True ,
95
115
)
96
116
except ValueError as e :
97
- raise BadRequestException (str (e ))
117
+ raise UnsupportedMediaException (str (e ))
118
+
98
119
except ThumbnailProcessNoop :
99
120
thumbnail = payload
100
121
else :
0 commit comments