11-29-2017 04:04 AM
hi all,
I am figuring out a way to base64 encode images . please help. I think base64 function is for text and not for images
11-29-2017 07:34 AM
You can use the Binary to Document Snap to base64-encode a binary stream into a document with a property that contains the encoded value.
11-29-2017 11:08 PM
tried this but i see difference in encoded values from using snaplogic functions and different online encoders available. may be a lot other things are getting encoded apart from image data. ie $content availble from file redaer has much more data than the actual image
11-30-2017 08:03 AM
Hope this helps
11-29-2017 09:59 AM
Long before the Binary to Document snap was developed and available, I used a Script snap. I should look at the Binary to Document snap to see if it improves my pipeline, but if that snap doesn’t serve your purpose, here’s a snippet of Python that may help. You need to import base64.
(note: this code is 3 years old, and I’m not a Pyhton guru, so certain code & exception handling may be improved)
try:
with open(filepath2, "rb") as f:
bytes = ""
byte = f.read(1)
while byte != b"":
bytes = bytes + byte
byte = f.read(1)
if byte != b"":
bytes = bytes + byte
output = base64.b64encode(bytes)
data2.put('IMAGE',output)
self.output.write(data2)
except Exception as e:
map = java.util.HashMap()
map.put('FILENAME',filepath2)
map.put('Exception',str(e.errno) + ": " + e.strerror)
self.error.write(map)