Class 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 of FileItems. This is the wrapper accessible from in-document scripts.
    Version:
    $Id: 4e2a22966c75fe4f27f0f36e4daf753e45048d9b $
    • Method Detail

      • cleanFileList

        public void cleanFileList()
        Deletes all temporary files of the upload.
      • loadFileList

        public void loadFileList()
                          throws XWikiException
        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 reached.
      • loadFileList

        public void loadFileList​(long uploadMaxSize,
                                 int uploadSizeThreashold,
                                 String tempdir)
                          throws XWikiException
        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.
      • getFileItems

        public List<org.apache.commons.fileupload.FileItem> getFileItems()
        Allows to retrieve the current list of uploaded files, as a list of FileItems. 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 use getFileItems()
        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, use getFileItemAsString(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 use getFileItems()
        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 use getFileItems()
        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 use getFileItemNames()
        Parameters:
        formfieldName - The name of the form field.
        Returns:
        The file name, or null if no file was uploaded for that form field.