Fix minio localhost public URL by proxying through backend

This commit is contained in:
2026-09-25 17:54:33 +05:30
parent 9dd0601a22
commit ed1084bd8d
2 changed files with 14 additions and 1 deletions

View File

@@ -1847,3 +1847,16 @@ def verify_payment(payload: VerifyPaymentPayload, session: Session = Depends(get
return {"success": True, "tier": user.tier.value}
@app.get("/api/storage/{bucket}/{object_name:path}", tags=["Storage"])
def get_storage_file(bucket: str, object_name: str):
import storage
import io
from fastapi.responses import StreamingResponse
file_bytes = storage.get_file(object_name)
if not file_bytes:
from fastapi import HTTPException
raise HTTPException(status_code=404, detail="File not found")
content_type = "application/pdf" if object_name.endswith(".pdf") else "application/octet-stream"
return StreamingResponse(io.BytesIO(file_bytes), media_type=content_type)

View File

@@ -74,7 +74,7 @@ def upload_file(file_content: bytes, object_name: str, content_type: str = "appl
# Construct public URL (from browser's point of view, it connects to localhost:9000)
# We can resolve this dynamically by returning a path like /api/uploads/ or direct localhost:9000 link
public_url = f"http://localhost:9000/{MINIO_BUCKET}/{object_name}"
public_url = f"/api/storage/{MINIO_BUCKET}/{object_name}"
logger.info(f"Successfully uploaded {object_name} to Minio. URL: {public_url}")
return public_url
except Exception as e: