Package de.xima.fc.form.upload
Class AjaxUploadManager
- java.lang.Object
-
- de.xima.fc.form.upload.AjaxUploadManager
-
public final class AjaxUploadManager extends Object
Manages the files uploaded via AJAX before the form was submitted. Files uploaded via AJAX are stored in a temporary directory. The name of this directory is stored in the form request session and deleted when the form request session is closed.The form request session contains a mapping between the name of the name of the upload element (e.g.
upl1_dyn_fs_1
) and the descriptor of the file that was uploaded. The descriptor stores the path to the temporary upload file, as well as some metadata such as the file name and content type and a unique UUID for the file.The process to upload a file via AJAX is as follows:
- The user selects a file in the browser via a native file input element
- The client side JavaScript generates a unique AJAX UUID and stores it in a hidden input field next to the file input element
- The client side JavaScript sends the name of the file input element, the AJAX UUID, the file's contents and its meta data to the server
- The server creates a new entry in the upload map in the form request session
- The user later submits the form to the server. This sends the UUID in the hidden input field
- For each upload element for which an AJAX UUID was submitted, the server retrieves the entry in the upload map.
If a matching entry is found, it merges the uploaded file into the
request data
.
- Since:
- 7.0.11
- Author:
- XIMA MEDIA GmbH
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addAllTo(FRQSession session, IParameterContext paramCtx)
Adds all AJAX uploads from the session to the given parameters wrapper.static void
addAllToParametersWrapper(FRQSession session, ParameterWrapper parameterWrapper)
Adds all AJAX uploads from the session to the given parameters wrapper.static void
addUpload(FRQSession session, String id, AjaxUploadDetails details, InputStream content)
Registers an uploaded file with the given session.static FetchUploadDataResult
fetchUploadData(FRQSession session, String id, String uploadName)
Fetches the data registered with the given upload name, when it matches the ID.static Map<String,UploadFileMeta>
getUploadFileMeta(FRQSession session)
Finds all existing uploads that were registered in the given session (and not yet removed).static void
removeUpload(FRQSession session, long time, String fieldName)
Removes an uploads that was added via previously.
-
-
-
Method Detail
-
addAllTo
public static void addAllTo(FRQSession session, IParameterContext paramCtx)
Adds all AJAX uploads from the session to the given parameters wrapper.- Parameters:
session
- Current form request session.paramCtx
- Parameters context to which to add uploads.
-
addAllToParametersWrapper
public static void addAllToParametersWrapper(FRQSession session, ParameterWrapper parameterWrapper)
Adds all AJAX uploads from the session to the given parameters wrapper.- Parameters:
session
- Current form request session.parameterWrapper
- Parameters wrapper to which to add uploads.
-
addUpload
public static void addUpload(FRQSession session, String id, AjaxUploadDetails details, InputStream content) throws AjaxUploadException
Registers an uploaded file with the given session.- Parameters:
session
- Form request session with the state, where the uploaded items are stored.id
- Unique ID of the upload.details
- Details of the upload.content
- Data of the file.- Throws:
AjaxUploadException
- When the upload could not be added, such as when the temporary directory could not be created.
-
fetchUploadData
public static FetchUploadDataResult fetchUploadData(FRQSession session, String id, String uploadName) throws IOException
Fetches the data registered with the given upload name, when it matches the ID.- Parameters:
session
- Form request session with the state.id
- The unique ID of the file.uploadName
- Unique name or ID of the upload.- Returns:
- The data of the given upload.
- Throws:
IOException
- When the data could not be fetched or does not exist.
-
getUploadFileMeta
public static Map<String,UploadFileMeta> getUploadFileMeta(FRQSession session)
Finds all existing uploads that were registered in the given session (and not yet removed).- Parameters:
session
- Form request session with the state.- Returns:
- A map with all existing uploads. Key is the file ID.
-
removeUpload
public static void removeUpload(FRQSession session, long time, String fieldName)
Removes an uploads that was added via previously.- Parameters:
session
- Form request session with the state.time
- Time when the request was made. Note that this is not required to correspond to a physical time, the only requirement for this number is that a larger number implies that a request was made later.fieldName
- Unique name or ID of the upload.
-
-