diff --git a/marimo/_output/utils.py b/marimo/_output/utils.py index 4e9e92307c6..fa2a520e8a8 100644 --- a/marimo/_output/utils.py +++ b/marimo/_output/utils.py @@ -8,6 +8,7 @@ def build_data_url(mimetype: KnownMimeType, data: bytes) -> str: + # `data` must be base64 encoded str_repr = data.decode("utf-8").replace("\n", "") return f"data:{mimetype};base64,{str_repr}" diff --git a/marimo/_server/export/exporter.py b/marimo/_server/export/exporter.py index df6a6fd4ba9..fe6d9f738d1 100644 --- a/marimo/_server/export/exporter.py +++ b/marimo/_server/export/exporter.py @@ -1,6 +1,7 @@ # Copyright 2024 Marimo. All rights reserved. from __future__ import annotations +import base64 import io import mimetypes import os @@ -61,7 +62,8 @@ def export_as_html( None, ) files[filename_and_length] = build_data_url( - cast(KnownMimeType, mime_type), buffer_contents + cast(KnownMimeType, mime_type), + base64.b64encode(buffer_contents), ) config = _deep_copy(DEFAULT_CONFIG)