Send feedback
Function: base64.encode
Stay organized with collections
Save and categorize content based on your preferences.
Encodes given bytes to Base64 text.
Arguments
Arguments
data
bytes
The input to be encoded.
padding
boolean
Specifies whether padding characters should be used to align the output to a multiple of 4 bytes (default: true
).
Returns
The encoded Base64 output, as a string.
Examples
For more information, see
Returning 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 topic
call : googleapis.pubsub.v1.projects.topics.publish
args :
topic : '${"projects/" + project + "/topics/" + topic}'
body :
messages :
- data : '${base64Msg}'
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-28 UTC.
Need to tell us more?
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Function: base64.encode\n\nEncodes given bytes to Base64 text.\n\nArguments\n---------\n\nReturns\n-------\n\nThe encoded Base64 output, as a string.\n\nExamples\n--------\n\nFor more information, see\n[Returning bytes](https://cloud.google.com/workflows/docs/reference/syntax/datatypes.md#bytes). \n\n```yaml\n# Encode message to JSON bytes, then encode bytes to Base64 text\n- init:\n assign:\n - project: '${sys.get_env(\"GOOGLE_CLOUD_PROJECT_ID\")}'\n - topic: TOPIC_ID\n - message:\n hello: world\n - base64Msg: '${base64.encode(json.encode(message))}'\n- publish_message_to_topic: # publishes message to Pub/Sub topic\n call: googleapis.pubsub.v1.projects.topics.publish\n args:\n topic: '${\"projects/\" + project + \"/topics/\" + topic}'\n body:\n messages:\n - data: '${base64Msg}'\n```"]]