Skip to Content
author's profile photo Former Member
Former Member

Read attachment content in Mapping

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Posted on May 14, 2009 at 08:04 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 14, 2009 at 08:18 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 18, 2009 at 09:42 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • 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;

  • author's profile photo Former Member
    Former Member
    Posted on Jun 15, 2009 at 02:07 PM

    Problem Solved

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.