Accessing Uploaded Files

  Written by The Jahia Team
 
Developers
   Estimated reading time:

This document describes the technical approach to accessing and using files that were uploaded during form submission.

Files are propagated to all actions in parameters and can be referenced by the input name i.e. file-upload_0_2

With SaveToJCR Action

When creating an action that requires accessing an uploaded file from the JCR, SaveToJCR action must be the FIRST action placed on a form!

File paths are replaced by absolute url after SaveToJCR action executes. The result of asking for "file-upload_0_2" is: exampleUrl; Which is the url of the file in JCR.

[*Note encoded characters should be replaced by their respective value]

 

You are then able to retrieve the file node by making a call: session.getNode(url);

Without SaveToJCR Action

When files are uploaded, they are saved under the server’s default temporary directory. For Tomcat it would be saved under tmp folder. The file path is provided in the parameters variable of the action. Access it by specifying the name of the file input  i.e. file-upload_0_2

You are able to also access the original file name and file type. 

Action Ordering

Form Factory does not restrict you in the composition of your actions.

 

In terms of action ordering, you have full control of how to order actions.

When it comes to form submission, there should be no difference as to which action is performed first, actions do not interact with each other.

 

Code can be adapted to work with raw files directly from tmp folder, in this case SaveToJCR is not required.

If a later action requires the file to be in the JCR, SaveToJCR should be placed before said action.