Convert an Uint8Array to a base64 encoded string

Encode byte values as base64 with btoa.

JavaScript Version 1.0.0 · MIT · .md

convert-an-uint8-array-to-a-base64-encoded-string.js
function bytesToBase64(bytes) { return btoa(String.fromCharCode(...bytes)); }

Input & expected output

Input

[
  72,
  101,
  108,
  108,
  111
]

Expected output

"SGVsbG8="

The edge case

Input

[]

Expected output

""

Know the limits

  • Spreading is fine for the lab’s 1,000 bytes. For files, use Buffer.from(bytes).toString("base64") in Node.js or encode in chunks.
  • This is the encoding Oveyon expects in an attachment’s content field.

The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.

Source & maintenance

Based on Convert an uint8 array to a base64 encoded string from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.

Uses String.fromCharCode with spread instead of building an array of characters; bytes validated 0–255. Original MDX retained as inert source evidence.

Maintained by Oveyon. Source commit: 14b481cf60df. Read the license.

Local fixture scope · Node.js 22.23.2 · reviewed October 28, 2026. No external service is required.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.