I have a binary files which needs to be sent as a string to a third-party web-service. Turns out it requires that it needs to be base64 encoded.
In ruby I use the following:
body = body << Base64.b64encode(IO.read("#{@postalcard.postalimage.path}"))
body is a strong which conists of a bunch of strings as parameters.
Does this look right? (the file is loaded into the model Postalcard using paperclip)
Thanks.
Base64.b64encodeprints out the base 64 encoded version of 60 char length by default. For example, if I will doIf I give it a length, lets say 4
But if you dont want to print out the encoded string to stdout and only return its value, which I think what you need, then use