fix(effi-ocr): handle None content-type by guessing from filename extension
This commit is contained in:
@@ -61,12 +61,18 @@ async def ocr_image(
|
|||||||
"""
|
"""
|
||||||
logger.info(f"OCR demandé - lang: {lang}, fichier: {file.filename}")
|
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']
|
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(
|
raise HTTPException(
|
||||||
status_code=400,
|
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:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user