Skip to content

Commit

Permalink
fix: base64 encode vfile buffers in html export (marimo-team#1441)
Browse files Browse the repository at this point in the history
Fixes a bug in which notebooks containing images and other media
couldn't be exported as HTML
  • Loading branch information
akshayka authored May 22, 2024
1 parent 29338ee commit da6675d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions marimo/_output/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down
4 changes: 3 additions & 1 deletion marimo/_server/export/exporter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations

import base64
import io
import mimetypes
import os
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit da6675d

Please sign in to comment.