Best way to base64encode a jpeg file ?

Monte Goulding monte.goulding at livecode.com
Thu Feb 6 18:23:16 EST 2025



> On 7 Feb 2025, at 9:54 AM, Bob Sneidar via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> Hi Monte. 
> 
> Are you saying a base64encode string CAN contain the characters you listed? I’m talking about dash, underscore and equal. Or is that reference saying that plus and minus (dash) are interchangeable, along with the slash and underscore respectively?

Hi Bob

I’ll add some comments to the function to explain

function urlSafeBase64 pData
  local tEncoded
  put base64Encode(pData) into tEncoded
 
  // The engine’s base64Encode function formats the result as required for 
  // base 64 Content-Transfer-Encoding as discussed in RFC 4648
  // section 3.1 and has linefeeds at 76 characters so remove
  replace return with empty in tEncoded

  // The engine’s base64Encode encodes using the alphabet in RFC 4648
  // section 4 and needs to be mapped to the alphabet in section 5
  replace "+" with "-" in pData
  replace "/" with "_" in pData

  // = is used to pad base 64 encoded data and in many circumstances is not
  // required. This could be an option on this function because it is valid in
  // url safe base 64 as long is it is percent encoded after
  replace "=" with empty in tEncoded

  return tEncoded
end urlSafeBase64

> 
> Bob S
> 
> 
>> On Feb 6, 2025, at 1:51 PM, Monte Goulding via use-livecode <use-livecode at lists.runrev.com> wrote:
>> 
>> Hi Bob
>> 
>>> On 7 Feb 2025, at 3:28 AM, Bob Sneidar via use-livecode <use-livecode at lists.runrev.com> wrote:
>>> 
>>> I don’t see any of those characters on base64encoded strings.
>> 
>> 
>> They definitely can be int there. Se RFC 4648 section 4 and 5 encoding tables for reference.
>> 
>> https://datatracker.ietf.org/doc/html/rfc4648#section-5
>> 
>> Cheers
>> 
>> Monte
>> 
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode



More information about the use-livecode mailing list