cancel
Showing results for 
Search instead for 
Did you mean: 

Create attachment in PI from incoming file

Former Member
0 Kudos

Hello All,

Is it possible to create an attachment from incoming XML file and send the resulting XML + Attachment via an adaptor like(File adaptor/Proxy) to another system .

Example:

If I have an incoming XML with normal text data and it also has a <!cdata> tag containing binary data.

So in PI, I want retain the normal XML data but convert the binary data(part of cdata tag) into an attachment and then send the XML data along with this attachment to receiver adaptor/system.

Appreciate any pointers on :

1. If it is possible to do this.

2. any blogs/threads which might point me in right direction.

Thanks

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member181985
Active Contributor
0 Kudos

two things (works only if PI version >= 7.1)

1. First read the CDATA section base64 string data and convert to byte array using standard SAP Base64 API class.

2. then create attachment using SAP's mapping API

Ensure that you enable check box "Read Attachments" in operation mapping

UDF Code Snippet:-

import com.sap.aii.utilxi.base64.api.*; //only in UDF import section not in code section

 

ByteArrayOutputStream baos = new ByteArrayOutputStream();

baos.write(Base64.decode("<base64stringdata_from_CDATATags>")); //write your logic to get CDATA string here

GlobalContainer globalContainer = container.getGlobalContainer();   

OutputAttachments outputAttachments = globalContainer.getOutputAttachments();   

 

try   

{   

        Attachment newopAttachment = outputAttachments.create("attachmentName", baos);    

        outputAttachments.setAttachment(newopAttachment);   

}   

catch (Exception e)   

{   

            e.printStackTrace();   

}   

 

return   "1";   

Former Member
0 Kudos

Hi,

check Praveen's reply:

http://scn.sap.com/message/13457673

Thanks

Amit Srivastava