Forum Discussion
del
9 years agoContributor III
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)