cogAttach to a document a file stored on a distant server, accessible remotely
Developed by


0 Votes
LicenseGNU Lesser General Public License 2.1


How to attach a distant file to a XWiki document, programmatically

In groovy, with programming rights :

    try {
     URL file = new URL  ("http://server/path/to/file")

     // 1. get the file via a HTTP connection
     def connection = file.openConnection();
     def text = connection.content.text

     // 2. attach it and save the desired document
     def targetDoc = xwiki.getDocument("XWiki.TargetDocument")
      targetDoc.addAttachment("filename.ext", text.bytes);

    } catch (Exception e) {
      println( e.message )

You can use this script in a Scheduler Job to automatically get fresh data/file as frequently as you need it !

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Tags: groovy
Created by Jerome on 2008/09/24 11:41

Get Connected