Last modified by Eugen Colesnicov on 2019/10/02 14:13

From version < 2.1 >
edited by Eugen Colesnicov
on 2019/10/02 14:01
To version < 3.1 >
edited by Thomas Mortagne
on 2019/10/02 14:10
< >
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -xwiki:XWiki.etvc
1 +xwiki:XWiki.ThomasMortagne
ExtensionCode.ExtensionClass[0]
Description
... ... @@ -12,3 +12,7 @@
12 12  println (" rezult is = " + rzlt)
13 13  {{/groovy}}
14 14  {{/code}}
15 +
16 +{{warning}}
17 +Keep in mind that what this snippet is accessing a private field (##storageFile##) which might be renamed or modified any time so better not use that in an extension to hope to be stable.
18 +{{/warning}}
cogShows how is possible to get full path of an attachment on server (when file-storage using)
Developed by

Eugen Colesnicov

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

The following script is useful in case you need to get full (physical) path of an attachment on server (with file-storage using) - means at which folder & subfolder this file is physically store. In this example, snippet shows how to get path for attachment TestingData.xls attached to a current page. Of course, you can expand this snippet to get full path of attachment from other page or for list of attachments.

{{groovy}}
import com.xpn.xwiki.*;
import com.xpn.xwiki.api.*;
import com.xpn.xwiki.doc.*;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.net.URL;
rzlt = doc.getAttachment("TestingData.xls").getAttachment().getAttachment_content().storageFile.getAbsolutePath()
println (" rezult is = " + rzlt)
{{/groovy}}

Keep in mind that what this snippet is accessing a private field (storageFile) which might be renamed or modified any time so better not use that in an extension to hope to be stable.

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Get Connected