cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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:

Answers (2)

Answers (2)

former_member184720
Active Contributor
0 Kudos

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...

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

ambrish_mishra
Active Contributor
0 Kudos

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