Base64 String To Image In Mule

 

In this tutorial we will demonstrate how to convert Base64 String To Image In Mule

To create the image we would require the base64 content, to demonstrate I have converted a sample image file to base64 using below url and used the same base64 content to write the image in one of the local directory use file write operation.

https://www.base64-image.de/

Create a project in anypoint studio and configure the listener to trigger the flow

 

Base64 String To Image In Mule

 

Convert base64 string to binary and use mime type as application/octet-stream as shown below

Use fromBase64 dataweave function to convert base64 to binary

Base64 String To Image In Mule

 

Dataweave Expression

%dw 2.0

import * from dw::core::Binaries
output application/octet-stream
---
fromBase64(payload)

Reference: https://docs.mulesoft.com/mule-runtime/4.1/dw-binaries-functions-frombase64

Change the mime type to image/png

 

 

Write the file in one of the local directory using file write operation

 

Deploy and trigger the file, image is created in local directory

 

 

Sample tutorial: writeimagefile sample application

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Shani Jaiswal
Shani Jaiswal
5 years ago

Hi Team,
Very nice website where all topics are covered in a single platform. Keep up the good work.
One input : Here SetPayload is not mandatory . Its automatically getting converted to different formats like jpeg,png ,gif etc without explicitly mentioning the Mime Type in SetPayload

Last edited 5 years ago by Shani Jaiswal
Nishanth Reddy
5 years ago

Excellent material available for new beginers. Really liked your work !!!
Keep up good work, All the best !!!!!

Abhilash
Abhilash
1 year ago

Best website for beginners !!!