-
Notifications
You must be signed in to change notification settings - Fork 157
Example 06
###Managing subfolders: Using the object context
Imagine you host an artist library where users can upload files for an artist. You may want to store files of each artist in its own subfolder. You can use the objectContext feature (client side). The object context may be an unique artist name or an id. Whenever you post an object context along with your request, the handler will store the uploaded file in a subfulder with the value of the object context. 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 object 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">
...
<input type="hidden" name="objectContext" value="user123" />
...
</form>
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 $context = $('#objContext');
data.formData = { example: $context.val() };
});
Method 3: Manipulate the url and add objectContext to the querystring:
var fileUploadUrl = "/Backload/UploadHandler" + "&objectContext=user123";
Don't forget, to enable the `getInclSubFolders` attribute in the config, so the Backload. handler will search in subfolders:
<fileUpload getInclSubFolders="true" ... />
####Conclusion In this example we showed you how to store files with respect to its object context. For more information on how to include extra forms data before a client side request starts, consult the docs of the client side plugin.
Code examples: Example06
Backload. (Standard version): Copyright 2013, Steffen Habermehl, License (Standard version): MIT license
Professional and Enterprise (source code) version are available under a commercial license.
Follow us on Twitter: @Backload_MVC