Function: base64.encode Stay organized with collections Save and categorize content based on your preferences.
Encodes given bytes to Base64 text.
Arguments
| Arguments | |
|---|---|
data |
The input to be encoded. |
padding |
Specifies whether padding characters should be used to align the output to a multiple of 4 bytes (default: |
Returns
The encoded Base64 output, as a string.
Examples
For more information, seeReturning bytes.
# Encode message to JSON bytes, then encode bytes to Base64 text-init:assign:-project:'${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}'-topic:TOPIC_ID-message:hello:world-base64Msg:'${base64.encode(json.encode(message))}'-publish_message_to_topic:# publishes message to Pub/Sub topiccall:googleapis.pubsub.v1.projects.topics.publishargs:topic:'${"projects/"+project+"/topics/"+topic}'body:messages:-data:'${base64Msg}'
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.