Get Attachment from multiple pages and add it to one page

Hi everyone, i’m searching for a velocity function to add an attachment to a page.

#macro(changeAttachements $sectionChildDocument)
     #set($list=$sectionChildDocument.getAttachmentList())
     #foreach($attachment in $list)
       ##$doc.addAttachments()
     #end
 #end

The addAttachment() function neads the name of the attachment but the getAttachmentList() returns a list of types “Attachments”. So i want to know if it exist an addAttachment() function where i can pass an Attachment as parameter.

Hi, see https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Scripting/APIGuide/#HAddanAttachmenttoapage

Thanks

You can check all the addAttachment methods in xwiki-platform/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/api/Document.java at 360f07f98c17c80e7324ff2bbefbf757e4fe1376 · xwiki/xwiki-platform · GitHub

The Attachment object is xwiki-platform/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/api/Attachment.java at 262e5867460f97549699f9fd8df35d92887e5c40 · xwiki/xwiki-platform · GitHub and you can get from it the filename and the input stream.

Thanks, i’ll try other methods !