Package com.xpn.xwiki.plugin.fileupload
Class FileUploadPluginApi
- java.lang.Object
-
- com.xpn.xwiki.api.Api
-
- com.xpn.xwiki.plugin.PluginApi<FileUploadPlugin>
-
- com.xpn.xwiki.plugin.fileupload.FileUploadPluginApi
-
public class FileUploadPluginApi extends PluginApi<FileUploadPlugin>
Plugin that offers access to uploaded files. The uploaded files are automatically parsed and preserved as a list ofFileItem
s. This is the wrapper accessible from in-document scripts.- Version:
- $Id: 43c610c50b1439585185a384adf4a1971c391933 $
-
-
Constructor Summary
Constructors Constructor Description FileUploadPluginApi(FileUploadPlugin plugin, XWikiContext context)
API constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
cleanFileList()
Deletes all temporary files of the upload.String
getFileItem(String formfieldName)
Deprecated.not well named, usegetFileItemAsString(String)
String
getFileItemAsString(String formfieldName)
Allows to retrieve the contents of an uploaded file as a string.byte[]
getFileItemData(String formfieldName)
Allows to retrieve the contents of an uploaded file as a sequence of bytes.List<String>
getFileItemNames()
Retrieves the list of FileItem names.List<org.apache.commons.fileupload.FileItem>
getFileItems()
Allows to retrieve the current list of uploaded files, as a list ofFileItem
s.String
getFileName(String formfieldName)
This method returns the name of the first matching file with the formfieldName.void
loadFileList()
Loads the list of uploaded files in the context if there are any uploaded files.void
loadFileList(long uploadMaxSize, int uploadSizeThreashold, String tempdir)
Loads the list of uploaded files in the context if there are any uploaded files.-
Methods inherited from class com.xpn.xwiki.plugin.PluginApi
getInternalPlugin, getProtectedPlugin, setPlugin
-
Methods inherited from class com.xpn.xwiki.api.Api
convert, convert, convert, convertAttachments, getAuthorizationManager, getContextualAuthorizationManager, getXWikiContext, hasAccess, hasAccessLevel, hasAdminRights, hasProgrammingRights, hasWikiAdminRights
-
-
-
-
Constructor Detail
-
FileUploadPluginApi
public FileUploadPluginApi(FileUploadPlugin plugin, XWikiContext context)
API constructor.- Parameters:
plugin
- The wrapped plugin object.context
- Context of the request.- See Also:
PluginApi(com.xpn.xwiki.plugin.XWikiPluginInterface, XWikiContext)
-
-
Method Detail
-
cleanFileList
public void cleanFileList()
Deletes all temporary files of the upload.
-
loadFileList
public void loadFileList() throws XWikiException, AttachmentValidationException
Loads the list of uploaded files in the context if there are any uploaded files.- Throws:
XWikiException
- if the request could not be parsed, or the maximum file size was reachedAttachmentValidationException
- in case of error when validating the attachment (e.g., the maximum filesize is reached)
-
loadFileList
public void loadFileList(long uploadMaxSize, int uploadSizeThreashold, String tempdir) throws XWikiException, AttachmentValidationException
Loads the list of uploaded files in the context if there are any uploaded files.- Parameters:
uploadMaxSize
- Maximum size of the uploaded files.uploadSizeThreashold
- Threashold over which the file data should be stored on disk, and not in memory.tempdir
- Temporary directory to store the uploaded files that are not kept in memory.- Throws:
XWikiException
- if the request could not be parsed, or the maximum file size was reached.AttachmentValidationException
- in case of error when validating the attachment (e.g., the maximum filesize is reached)
-
getFileItems
public List<org.apache.commons.fileupload.FileItem> getFileItems()
Allows to retrieve the current list of uploaded files, as a list ofFileItem
s.loadFileList()
needs to be called beforehand- Returns:
- A list of FileItem elements.
-
getFileItemData
public byte[] getFileItemData(String formfieldName) throws XWikiException
Allows to retrieve the contents of an uploaded file as a sequence of bytes.loadFileList()
needs to be called beforehand. This method returns the contents of the first matching FileItem with the formfieldName. If you are dealing with multiple files with the same formfieldName you should usegetFileItems()
- Parameters:
formfieldName
- The name of the form field.- Returns:
- The contents of the file.
- Throws:
XWikiException
- if the data could not be read.
-
getFileItem
@Deprecated public String getFileItem(String formfieldName) throws XWikiException
Deprecated.not well named, usegetFileItemAsString(String)
Allows to retrieve the contents of an uploaded file as a string.loadFileList()
needs to be called beforehand. This method returns the contents of the first matching FileItem with the formfieldName. If you are dealing with multiple files with the same form field name you should usegetFileItems()
- Parameters:
formfieldName
- The name of the form field.- Returns:
- The contents of the file.
- Throws:
XWikiException
- Exception is thrown if the data could not be read.
-
getFileItemAsString
public String getFileItemAsString(String formfieldName) throws XWikiException
Allows to retrieve the contents of an uploaded file as a string.loadFileList()
needs to be called beforehand. This method returns the contents of the first matching FileItem with the formfieldName. If you are dealing with multiple files with the same form field name you should usegetFileItems()
- Parameters:
formfieldName
- The name of the form field.- Returns:
- The contents of the file.
- Throws:
XWikiException
- if the data could not be read.
-
getFileItemNames
public List<String> getFileItemNames()
Retrieves the list of FileItem names.loadFileList()
needs to be called beforehand.- Returns:
- List of strings of the item names
-
getFileName
public String getFileName(String formfieldName)
This method returns the name of the first matching file with the formfieldName. If you are dealing with multiple files with the same form field name you should usegetFileItemNames()
- Parameters:
formfieldName
- The name of the form field.- Returns:
- The file name, or
null
if no file was uploaded for that form field.
-
-