Try fix for Font files

This commit is contained in:
Anup Raj Gopinathan
2025-06-25 16:13:50 +02:00
parent 2e5159686b
commit e533a98b84
+16 -1
View File
@@ -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():