Skip to Content
avatar image
Former Member

How to Read the File name and File size of a Sender File attachment in PI

Hi,

We have a requirement of extracting the File Name and File size of an attachment which is picked up by the Sender File Adapter.The Sender File is picked up as an attachment through the Sender File Adapter. I need the File name and File size of the attachment.These two details are to be sent to the Target System.

Kindly suggest the logic as to how to achieve the same in the mapping.Is this possible through a UDF in the mapping?

Thanks,

Soundarya

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Nov 26, 2013 at 08:48 AM

    Hi Soundarya

    This UDF code will give you the attachment name and the size

    String attachmentID = null;
    GlobalContainer globalContainer = container.getGlobalContainer();
    InputAttachments inputAttachments = globalContainer.getInputAttachments();

    if(inputAttachments.areAttachmentsAvailable())
    {
    Collection<String> CollectionIDs = inputAttachments.getAllContentIds(true);
    Object[] arrayObj = CollectionIDs.toArray();
    attachmentID = (String)arrayObj[0];
    Attachment attachment = inputAttachments.getAttachment(attachmentID);
    int attachmentsize = attachment.getContent().length;
    return "Attachment Name : "+attachmentID +" Attachment Size : "+attachmentsize+" bytes";

    }

    else {
    return "no attachment found";
    }

    Output:


    pic1.jpg (27.2 kB)
    Add comment
    10|10000 characters needed characters exceeded

  • Nov 23, 2013 at 01:43 PM

    Hi Soudarya,

    Please go through the link http://scn.sap.com/message/13525886#13525886


    This should help you retrieve the file name of the attached file. Similarly you can get the file size.

    Hope it helps!

    Ambrish

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 25, 2013 at 10:09 PM

    With the help of a small UDF you can get the file name in the mapping.

    http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/07/01/retaining-soap-adapter-attachment-names

    However i dont see any getsize method for inputAttachments. May be you can get the size after attachment.getContent();

    You can give a try n confirm 😊

    Add comment
    10|10000 characters needed characters exceeded