Base64 Encode Function

It would be useful if we could send images and files as base64 encode strings in JSON payloads.

@Bellave_Jayaram, voted! I just spent the morning writing an Apps Script to this. It would be great if we could just have a function DECODE([Image])!

Here’s the script I came up with.

Thanks @GreenFlux!!

You are right, we can use your script approach but sometimes one needs to generate an encoded string on the fly and that is why I added the feature request.

This would be a very helpful feature for sending images to services outside of AppSheet. With the number of Image AI’s growing, I think this feature will only get more necessary in the future

3 Likes

@Bellave_Jayaram Do you know any way that from appsheet I can encode a text string in “base64”?

No, hence the feature request. @Adam, can you shed any light here?

1 Like

@Bellave_Jayaram, I know you’re looking for a method that avoids Apps Script, but what if the script is just to declare a custom function? Then you can apply the script via sheet formula, instead of having to invoke the script from AppSheet.

Screen Shot 2020-09-09 at 3.24.21 PM

Apps Script

Summary

/**
 * Convert input string to Base64Encoded.
 *
 * @param {string} The input cell.
 * @return {string} The encoded string.
 * @customfunction
 */
function base64Encode(input) {
  if (input != ''){
  return Utilities.base64Encode(input.toString(), Utilities.Charset.UTF_8);
  }
  
}
/**
 * Convert base64Encoded input string to decoded string.
 *
 * @param {string} The input cell.
 * @return {string} The decoded string.
  * @customfunction
 */
function base64Decode(input) {
  if (input != ''){
  return Utilities.base64Decode(input, Utilities.Charset.UTF_8).toString();
  }
  
}

1 Like

Thanks, yes that is a good option.

1 Like