cancel
Showing results for 
Search instead for 
Did you mean: 

Read attachment content in Mapping

Former Member
0 Kudos

Hi,

In PI 7.1 there is one option to read attachment content inside mapping using the api: "com.sap.aii.mapping.api".

To do that in operation mapping we have to check the option "ReadAttachments", to get the attachments in addition to the payload. If I check the Readattachments check box, message goes into the queue and the queue status is running.

Please help me to read the attachment content in mapping.

Thanks & Regards,

Yuga

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Problem Solved

Former Member
0 Kudos

Hey,

How was this problem solved...I am having trouble with excel and pdf contents. Appreciate any help. Thanks

Former Member
0 Kudos

Hi,

That issue has been solved,the problem is with the syntax.

Now I was able to get the attachment details,but i was not able to read the content of the attachment.

Here is my code:

String Content = "";

String AttachmentID ="";

GlobalContainer globalContainer = container.getGlobalContainer();

InputAttachments inputAttachments = globalContainer.getInputAttachments();

if(inputAttachments.areAttachmentsAvailable())

{

Collection<String> CollectionIDs = inputAttachments.getAllContentIds(true);

Object[] arrayObj = CollectionIDs.toArray();

int attachmentCount = arrayObj.length;

for(int i =0;i<attachmentCount;i++)

{

AttachmentID =(String) arrayObj<i>;

Attachment attachments =inputAttachments.getAttachment(AttachmentID);

Content = Content + attachments.getContent().toString();

}

}

return Content;

My requirement is to read all the attachment's.Attachment has XML content, so after reading I need to parse the xml content inside graphical mapping itself is there is any option to do like this.

Thanks & Regards,

Yuga

0 Kudos

Hey, how diid yyou read the attachment & Map in graphical editor further, any help is appreciated

JayChan
Active Participant
0 Kudos

check this link:

https://www.mkyong.com/java/how-do-convert-byte-array-to-string-in-java/

Since attachments.getContent() only return byte[]. The code should be modified like following to restore the data back into string form (if data is plain string)

      String Content = "";
      String AttachmentID ="";
          
      InputAttachments inputAttachments = container.getGlobalContainer().getInputAttachments();
      if(inputAttachments.areAttachmentsAvailable())
      {
          Collection<String> CollectionIDs = inputAttachments.getAllContentIds(true);
          Object[] arrayObj = CollectionIDs.toArray();
          int attachmentCount = arrayObj.length;
          for(int i =0;i<attachmentCount;i++)
          {
              AttachmentID =(String) arrayObj[i]; 
              Attachment attachments =inputAttachments.getAttachment(AttachmentID);
              String s = new String(attachments.getContent());
              Content = Content + s;
          }
          
      }
      return Content;

Former Member
0 Kudos

see [http://help.sap.com/javadocs/pi/SP3/xpi/index.html?com/sap/aii/mappingtool/tf7/rt/package]

for Interface InputAttachments

see [http://help.sap.com/javadocs/pi/SP3/xpi/index.html?com/sap/aii/mappingtool/tf7/rt/package]

for Interface OutputAttachments

prateek
Active Contributor
0 Kudos

To begin, you must use InputAttachments class to read the attachment from source message and OutputAttachments class to write the attchments to target message.

Regards,

Prateek