Upload files into a Structr application


The following HTML form can be used to upload files into a Structr application. The uploading user (if logged in) will automatically be the owner of the files.

<form action="/struct/upload" method="post" enctype="multipart/form-data">
    <input type="hidden" name="parent" value="${first(find('File', 'name', 'uploads))}" /> 
    <input type="hidden" name="redirectOnSuccess" value="/success-page?newFile=" />
    <input type="hidden" name="appendUuidOnRedirect" value="true" />
    <input type="hidden" name="visibleToPublicUsers" value="true" /> 
    <input type="file" />
    <input type="submit" value="Upload!" />

Note the action attribute of the form. That is the URL of the Structr upload servlet which will handle the request. The method and enctype attributes contain the default values necessary for uploading files.

The important part are the <input> fields inside the form. You can set arbitrary properties, such as the parent folder (which will be set to the uploads folder if one exists). The name of the uploaded file will be set automatically.

The new feature for consists of the two parameters redirectOnSuccess and appendUuidOnRedirect, which can be used to instruct Structr to redirect the browser to a custom URL when the upload is finished. If you supply appendUuidOnRedirect with a value of true, you can for example redirect the user to a new page with a detail view of the page he/she just uploaded.

The above form will redirect the user to the following URL when the upload is finished, provided that the UUID of the uploaded file is de1067b758b24ee08b57021eae8659dd:



The <input type="file" /> field must be the last input field in the form except for the submit field!


About this article
Last change 2017-05-04