Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: base64 encode vfile buffers in html export (#1441)

Akshay Agrawalda6675d65422
diff --git a/marimo/_output/utils.py b/marimo/_output/utils.py
index 4e9e92307c..fa2a520e8a 100644
--- a/marimo/_output/utils.py
+++ b/marimo/_output/utils.py
@@ -8,6 +8,7 @@ from marimo._messaging.mimetypes import KnownMimeType
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 df6a6fd4ba..fe6d9f738d 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 @@ class Exporter:
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)