@@ -1231,8 +1231,22 @@ def __init__(self,
12311231 # If we don't get a stream as param:
12321232 # Create a stream from the file path in format_or_path
12331233 path = str (format_or_path )
1234- mime_type = mimetypes .guess_type (
1235- path )[0 ]
1234+
1235+ # Extract file extension:
1236+ # path_obj.suffix returns the extension including
1237+ # the dot (e.g., ".jpg", ".png").
1238+ # If no extension exists, suffix returns empty string,
1239+ # so file_extension will be ""
1240+ path_obj = Path (path )
1241+ file_extension = path_obj .suffix .lower () if path_obj .suffix else ""
1242+
1243+ if file_extension == ".dng" :
1244+ # mimetypes guesses the wrong type for dng,
1245+ # so we bypass it and set the correct type
1246+ mime_type = "image/dng"
1247+ else :
1248+ mime_type = mimetypes .guess_type (
1249+ path )[0 ]
12361250
12371251 if not mime_type :
12381252 raise C2paError .NotSupported (
@@ -2279,8 +2293,22 @@ def sign_file(self,
22792293 Raises:
22802294 C2paError: If there was an error during signing
22812295 """
2282- # Get the MIME type from the file extension
2283- mime_type = mimetypes .guess_type (str (source_path ))[0 ]
2296+ # Extract file extension:
2297+ # path_obj.suffix returns the extension
2298+ # including the dot (e.g., ".jpg", ".png")
2299+ # If no extension exists, suffix returns empty string,
2300+ # so file_extension will be ""
2301+ file_extension = ""
2302+ path_obj = Path (source_path )
2303+ file_extension = path_obj .suffix .lower () if path_obj .suffix else ""
2304+
2305+ if file_extension == ".dng" :
2306+ # mimetypes guesses the wrong type for dng,
2307+ # so we bypass it and set the correct type
2308+ mime_type = "image/dng"
2309+ else :
2310+ mime_type = mimetypes .guess_type (str (source_path ))[0 ]
2311+
22842312 if not mime_type :
22852313 raise C2paError .NotSupported (
22862314 f"Could not determine MIME type for file: { source_path } " )
0 commit comments