fix(effi-ocr): handle None content-type by guessing from filename extension

This commit is contained in:
Folzo
2026-04-11 02:13:11 +02:00
parent f17b62737a
commit 35486244fe
+9 -3
View File
@@ -61,12 +61,18 @@ async def ocr_image(
"""
logger.info(f"OCR demandé - lang: {lang}, fichier: {file.filename}")
# Vérifier le type de fichier
# Déterminer le type MIME (avec fallback depuis l'extension)
content_type = file.content_type
if content_type is None:
import mimetypes
content_type, _ = mimetypes.guess_type(file.filename)
content_type = content_type or 'application/octet-stream'
allowed_types = ['image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/tiff', 'image/webp']
if file.content_type not in allowed_types:
if content_type not in allowed_types:
raise HTTPException(
status_code=400,
detail=f"Type de fichier non supporté: {file.content_type}. Types acceptés: {', '.join(allowed_types)}"
detail=f"Type de fichier non supporté: {content_type}. Types acceptés: {', '.join(allowed_types)}"
)
try: