From e533a98b844850448e3a790ae9232b45cebc44ea Mon Sep 17 00:00:00 2001 From: Anup Raj Gopinathan Date: Wed, 25 Jun 2025 16:13:50 +0200 Subject: [PATCH] Try fix for Font files --- src/run.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/run.py b/src/run.py index b5d14b6..b36fb7e 100644 --- a/src/run.py +++ b/src/run.py @@ -7,6 +7,7 @@ from logging.handlers import RotatingFileHandler from flask import render_template from flask_migrate import upgrade import awsgi +import base64 app = create_app() @@ -44,7 +45,21 @@ if __name__ == '__main__': app.run(host='0.0.0.0', port=5004) def lambda_handler(event, context): - return awsgi.response(app, event, context) + response = awsgi.response(app, event, context) + headers = response.get("headers", {}) + content_type = headers.get("Content-Type", headers.get("content-type", "")) + # List of binary content types (add more as needed) + binary_types = ["application/octet-stream", "image/", "application/pdf"] + if any(content_type.startswith(b) for b in binary_types): + # Base64 encode the body if not already encoded + if not response.get("isBase64Encoded"): + body = response["body"] + if isinstance(body, str): + # Try to encode as latin1 to preserve binary data + body = body.encode("latin1") + response["body"] = base64.b64encode(body).decode("utf-8") + response["isBase64Encoded"] = True + return response def lambda_handler_upgrade_db(event, context): with app.app_context():