How to send Byte array of an image from the custom action as a response ?
with open("C:/Downloads/myimage.jpeg", "rb") as image:
f = image.read()
b = bytearray(f)
image = Image.open(io.BytesIO(b))
dispatcher.utter_template("utter_thanks", tracker, False, image=image )
I got TypeError: Object of type JpegImageFile is not JSON serializable.
Is there any solution.
Can you instead use the filepath to the image, i.e. file:///C:\Downloads\myimage.jpeg">? I don’t believe there is a way to send a byte array of an image at the moment.
I think this would have to be handled by your output channel. So you would e.g. convert your bytes to a string to get them to the output channel, and then do something with that string in your output channel, depending on how your channel accepts the byte formatted request. This might be helpful: python - How to convert image data so it can be JSON serializable and vice versa - Stack Overflow. I don’t think that any of our current output channels support this.