@@ -315,11 +315,17 @@ async def generate():
315315 try :
316316 blob_service = await get_blob_service ()
317317 if response .get ("image_base64" ):
318- image_url = await blob_service .save_generated_image (
318+ blob_url = await blob_service .save_generated_image (
319319 conversation_id = conversation_id ,
320320 image_base64 = response ["image_base64" ]
321321 )
322- response ["image_url" ] = image_url
322+ # Convert blob URL to proxy URL for frontend access
323+ # blob_url format: https://account.blob.core.windows.net/container/conv_id/filename.png
324+ # proxy URL format: /api/images/conv_id/filename.png
325+ if blob_url :
326+ parts = blob_url .split ("/" )
327+ filename = parts [- 1 ] # e.g., "20251202222126.png"
328+ response ["image_url" ] = f"/api/images/{ conversation_id } /{ filename } "
323329 except Exception as e :
324330 logger .warning (f"Failed to save image to blob storage: { e } " )
325331
@@ -342,6 +348,8 @@ async def generate():
342348 )
343349
344350 # Save the full generated content for restoration
351+ # Note: image_base64 is NOT saved to CosmosDB as it exceeds document size limits
352+ # Images will only persist if blob storage is working
345353 generated_content_to_save = {
346354 "text_content" : response .get ("text_content" ),
347355 "image_url" : response .get ("image_url" ),
@@ -376,6 +384,40 @@ async def generate():
376384 )
377385
378386
387+ # ==================== Image Proxy Endpoint ====================
388+
389+ @app .route ("/api/images/<conversation_id>/<filename>" , methods = ["GET" ])
390+ async def proxy_generated_image (conversation_id : str , filename : str ):
391+ """
392+ Proxy generated images from blob storage.
393+ This allows the frontend to access images without exposing blob storage credentials.
394+ """
395+ try :
396+ blob_service = await get_blob_service ()
397+ await blob_service .initialize ()
398+
399+ blob_name = f"{ conversation_id } /{ filename } "
400+ blob_client = blob_service ._generated_images_container .get_blob_client (blob_name )
401+
402+ # Download the blob
403+ download = await blob_client .download_blob ()
404+ image_data = await download .readall ()
405+
406+ # Determine content type from filename
407+ content_type = "image/png" if filename .endswith (".png" ) else "image/jpeg"
408+
409+ return Response (
410+ image_data ,
411+ mimetype = content_type ,
412+ headers = {
413+ "Cache-Control" : "public, max-age=86400" , # Cache for 24 hours
414+ }
415+ )
416+ except Exception as e :
417+ logger .exception (f"Error proxying image: { e } " )
418+ return jsonify ({"error" : "Image not found" }), 404
419+
420+
379421# ==================== Product Endpoints ====================
380422
381423@app .route ("/api/products" , methods = ["GET" ])
0 commit comments