Skip to content

Example 07

Steffen Habermehl edited this page Mar 23, 2017 · 8 revisions

Managing subfolders: Using the upload context

In example 6 we've created an artists library, where a specific artist has the object context. Let's go a bit further. We want to categorize the work of an artist in youth period, adult period and late period. Files for these categories should be stored in subfolders of the artist with the current object context. This task can be automatically done by the upload context feature (client side). Whenever you post an upload context along with your request, the handler will store the uploaded file in the appropriate subfolder with the name of the uploadContext value. The uploadContext value can hold multiple values separated by semicolon which lead to an even more complex folder structure (see example). The easiest way is to place an input field (hidden or text) or select form field within the <form> tag. Another way is to manipulate the url or body before the request starts. (see: How to submit additional form data. Note: On GET requests (return uploaded files), subfolders are ignored by default, so the handler will not return files in subfolders. You have to set the attribute getInclSubFolders="true" in the config.

How to setup upload context subfolders

Method 1: Just include an input field (type hidden or text) or a select field within the <form> tag:

    <form id="fileupload" action="/Backload/UploadHandler" method="POST" enctype="multipart/form-data">
        // Note: If objectContext is empty, uploadContext subfolders are in the global context.
        <input type="hidden" name="objectContext" value="raffael" />
        <input type="hidden" name="uploadContext" value="adult_period" />

Method 2: Use the client side JQuery File Upload Plugin to send extra forms data:
    $('#fileupload').bind('fileuploadsubmit', function (e, data) {
        // The example input, doesn't have to be part of the upload form:
        var $oc = $('#objContext');
        var $uc = $('#upContext');
        data.formData = { objectContext: $oc.val() , uploadContext: $uc.val() };
Method 3: Manipulate the url and add `objectContext` and `uploadContext` to the querystring:
    var handlerUrl = "/Backload/FileHandler?" + "objectContext=raffael&uploadContext=adult_period";

Don't forget, to enable the `getInclSubFolders` attribute in the config, so the Backload. handler will search in subfolders:
    <backload getInclSubFolders="true" ... />


In this example we showed you how to categorize uploaded files in subfolders of an object that has the current object context. Note: You do not need to use objectContext. If objectContext is an empty string (or not provided in the request) the subfolders of the upload context will be stored in the global context. Try the "Complex structure" value of the periods select element. It strores files in a complex subfolder structure. The value of "Complex structure" is "complex1;complex2;complex3". This will lead to the following file path: "[objectContext]/complex1/complex2/complex3/[uploaded file]. For more information on how to include extra forms data before a client side request starts, consult the docs of the client side plugin.


You can’t perform that action at this time.