Fix téléchargement ICS : encodage RFC 5987 pour noms de fichiers non-ASCII
Le header Content-Disposition avec filename="Là_où_bat_le_cœur.ics" causait une erreur 500 car les caractères non-ASCII ne sont pas valides en HTTP. Correction avec filename*=UTF-8''<url-encoded> (RFC 5987). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+5
-2
@@ -11,6 +11,8 @@ from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from urllib.parse import quote
|
||||
|
||||
from fastapi import FastAPI, Depends, File, HTTPException, Request, Response, UploadFile, Cookie
|
||||
from fastapi.responses import FileResponse, StreamingResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
@@ -280,9 +282,10 @@ async def download_ics(
|
||||
ics_path = DATA_DIR / "jobs" / job_id / filename
|
||||
if not ics_path.exists():
|
||||
raise HTTPException(404, "Fichier introuvable")
|
||||
encoded = quote(filename, safe='')
|
||||
return FileResponse(
|
||||
ics_path, media_type="text/calendar", filename=filename,
|
||||
headers={"Content-Disposition": f'attachment; filename="{filename}"'},
|
||||
ics_path, media_type="text/calendar",
|
||||
headers={"Content-Disposition": f"attachment; filename*=UTF-8''{encoded}"},
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user