Get physical path on server of an attachment
Version 4.1 by Eugen Colesnicov on 2019/10/02 14:13
Shows how is possible to get full path of an attachment on server (when file-storage using) |
Type | |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Table of contents
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}}
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}}