Replies: 2 comments
-
Hey @mcgrimm! 👋 I'm here to help you with bug fixes, answer questions, and even guide you on becoming a contributor. If you need anything, just give me a shout! I found some relevant information that might help you with handling base64 images in Dify. The Dify API documentation provides methods for decoding base64 encoded images, which include checking if the encoded string is plain base64 without a MIME type prefix, and extracting MIME type and image data from a base64 encoded string with a MIME type prefix. Here's a snippet of the relevant code: @staticmethod
def _decode_image(base64_image: str) -> tuple[str, bytes]:
if DallE3Tool._is_plain_base64(base64_image):
return "image/png", base64.b64decode(base64_image)
else:
return DallE3Tool._extract_mime_and_data(base64_image)
@staticmethod
def _is_plain_base64(encoded_str: str) -> bool:
return not encoded_str.startswith("data:image")
@staticmethod
def _extract_mime_and_data(encoded_str: str) -> tuple[str, bytes]:
mime_type = encoded_str.split(";")[0].split(":")[1]
image_data_base64 = encoded_str.split(",")[1]
decoded_data = base64.b64decode(image_data_base64)
return mime_type, decoded_data These methods can help you convert base64 images to a format suitable for API upload [1]. Additionally, there are similar discussions and issues that might provide more context or solutions:
These might offer additional insights or approaches to your problem. |
Beta Was this translation helpful? Give feedback.
-
@dosu thanks for quick respond . i still struggle how to pass the base 64 string into LLM , i did try firework.ai , their api playground tell me how to setup the json with base64 string, and run very well. so i think dify should have such capability. , just fyi below is the api of firework.ai. URI uri = URI.create("https://api.fireworks.ai/inference/v1/chat/completions"); |
Beta Was this translation helpful? Give feedback.
-
Self Checks
1. Is this request related to a challenge you're experiencing? Tell me about your story.
Hello , i have an ERP system which want to send image to DIFY , but the image should in format of base64, currently i can't find any documentation about the base64 image input, i would like to run API to pass the base64 file to workflow.
can anyone have any suggestion or hints? i can't find any documentation in the API introduction so far. thank you very much.
Dify is the great tool , i hope i can use it in the industrial areas, the the integration ability should be very important.
thanks.
2. Additional context or comments
No response
3. Can you help us with this feature?
Beta Was this translation helpful? Give feedback.
All reactions