cancel
Showing results for 
Search instead for 
Did you mean: 

Base64 to image in PI

venkatagiri_gongadi
Participant
0 Kudos

Hi,

I have a interface like below,

Third party sends base64(Encoding) data in XML(file name,File type and Data ) and i need to convert it to image in PI and send it to receiver system.

The receiver system expecting image and file name in output.

Can you please provide me some inputs on this.

Cheers,

Giri

Accepted Solutions (0)

Answers (2)

Answers (2)

venkatagiri_gongadi
Participant
0 Kudos

Hi,

Below code is working for me but i am facing some issue on below points,

String f2e =  new String(BASE64Decoder.decode(var1.getBytes()));

AbstractTrace trace = container.getTrace();

String location = "\\\\\\F\\ImageTesting\\Target";

String fileName = "test1.jpg";

byte image[] = BASE64Decoder.decode(var1.getBytes());

try {

OutputStream stream = new FileOutputStream(new File(location+fileName));

stream.write(image);

stream.close();

} catch (IOException e) {

            trace.addWarning("Unable to write file :");

        } finally{

            trace.addWarning("File Written");

        }

return "success";

1.Image should be created in the folder in the target path.

2.More images should be created with different names if there are more than one entries in the input payload.(if there are 2 entries in a payload and it should be like image _1 and image_2 in a folder)

Can you please provide me your inputs on the same.

Cheers,

Giri

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Venkat,

You can use java mapping for your requirement. After converting the input stream (input payload) to string, extract the base64 data and decode using base64decode. Then write the output to output stream using the correct filename and extension.

Sample JAVA Mapping code using PI 7.1 API - Process Integration - SCN Wiki

Regards,

Mark

venkatagiri_gongadi
Participant
0 Kudos

Hi,

Please provide me UDF for this conversion as i am not able to use java mapping due to project constraints.

Cheers,

Giri

former_member186851
Active Contributor
0 Kudos

Hello Venkat,

Refer the below discussion and see if you can get the code

Ryan-Crosby
Active Contributor
0 Kudos

Hi Giri,

This would be more appropriately handled in the manner Mark mentioned as you need to take the information and decode and then write the outputstream (payload).  If you are working with UDFs then you are working with parts of an XML payload when you really need a binary stream as your output along with the dynamic configuration data.  It's a pretty simple java mapping overall to achieve such a requirement.

Regards,

Ryan Crosby