Package com.xpn.xwiki.web
Class UploadAction
- java.lang.Object
-
- com.xpn.xwiki.web.XWikiAction
-
- com.xpn.xwiki.web.UploadAction
-
- All Implemented Interfaces:
com.xpn.xwiki.internal.web.LegacyAction
@Component @Named("upload") @Singleton public class UploadAction extends XWikiActionAction that handles uploading document attachments. It saves all the uploaded files whose fieldname start withfilepath.- Version:
- $Id: 3224e9d8b449218784e0467f805c2cb17029b725 $
-
-
Field Summary
Fields Modifier and Type Field Description static StringFILE_FIELD_NAMEThe prefix of the accepted file input field name.-
Fields inherited from class com.xpn.xwiki.web.XWikiAction
ACTION_PROGRESS, componentDescriptor, container, execution, observation, waitForXWikiInitialization
-
-
Constructor Summary
Constructors Constructor Description UploadAction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaction(XWikiContext context)protected StringgetFileName(String fieldName, FileUploadPlugin fileupload, XWikiContext context)Extract the corresponding attachment name for a given file field.Stringrender(XWikiContext context)booleanuploadAttachment(String fieldName, String filename, FileUploadPlugin fileupload, XWikiDocument doc, XWikiContext context)Attach a file to the current document.-
Methods inherited from class com.xpn.xwiki.web.XWikiAction
answerJSON, cleanupComponents, csrfTokenCheck, csrfTokenCheck, execute, execute, getContextualAuthorizationManager, getCurrentMixedDocumentReferenceResolver, getCurrentScriptContext, getEntityNameValidationConfiguration, getEntityNameValidationManager, getFormClass, getLocalization, getLocalSerializer, getName, getProgress, getRealPath, getTranslatedDocument, handleRevision, initializeContainerComponent, initializeXWikiContext, initializeXWikiContext, isEntityReferenceNameValid, localizePlainOrKey, readFromTemplate, resolveTemplate, sendGlobalRedirect, sendRedirect, setContentLength, supportRedirections, writeAjaxErrorResponse
-
-
-
-
Field Detail
-
FILE_FIELD_NAME
@Unstable public static final String FILE_FIELD_NAME
The prefix of the accepted file input field name.- Since:
- 14.10
- See Also:
- Constant Field Values
-
-
Method Detail
-
action
public boolean action(XWikiContext context) throws XWikiException
- Overrides:
actionin classXWikiAction- Throws:
XWikiException
-
uploadAttachment
public boolean uploadAttachment(String fieldName, String filename, FileUploadPlugin fileupload, XWikiDocument doc, XWikiContext context) throws XWikiException
Attach a file to the current document.- Parameters:
fieldName- the target file fieldfilename-fileupload- theFileUploadPluginholding the form datadoc- the target documentcontext- the current request context- Returns:
trueif the file was successfully attached,falseotherwise.- Throws:
XWikiException- if the form data cannot be accessed, or if the database operation failed
-
getFileName
protected String getFileName(String fieldName, FileUploadPlugin fileupload, XWikiContext context) throws XWikiException
Extract the corresponding attachment name for a given file field. It can either be specified in a separate form input field, or it is extracted from the original filename.- Parameters:
fieldName- the target file fieldfileupload- theFileUploadPluginholding the form datacontext- the current request context- Returns:
- a valid attachment name
- Throws:
XWikiException- if the form data cannot be accessed, or if the specified filename is invalid
-
render
public String render(XWikiContext context) throws XWikiException
- Overrides:
renderin classXWikiAction- Throws:
XWikiException
-
-