| Thankful to Krajee! | to get more out of us. |
NOTE: The plugins on this site, strive to use a lot of CSS3 and HTML5 features in addition to JQuery. Hence, one may find either CSS3, HTML5 or a mix of both to achieve a plugin's requirements in many implementations.
An enhanced HTML 5 file input for Bootstrap 3.x with file preview for various files, offers multiple selection, and more. The plugin allows you a simple way to setup an advanced file picker/upload control built to work specially with Bootstrap CSS3 styles. It enhances the file input functionality further, by offering support to preview a wide variety of files i.e. images, text, html, video, audio, flash, and objects. In addition, it includes AJAX based uploads, dragging & dropping files, viewing upload progress, and selectively previewing, adding, or deleting files.
View a complete demo.
This plugin was initially inspired by this blog article and Jasny's File Input plugin. But the plugin has now matured with various additional features and enhancements to be a complete (yet simple) file management tool and solution for web developers.
With release v4.0.0, the plugin now supports AJAX based uploads using HTML 5 FormData and XHR2 protocol, which is supported in most modern browsers. It also has inbuilt support for AJAX based file deletion from the server. This thereby allows powerful features to append, add, remove files on the fly. The plugin also has added DRAG & DROP support for ajax uploads. In the event, the browser does not support FormData or XHR2, the plugin degrades it to a normal form submission.
The plugin will convert a simple HTML file input to an advanced file picker control. Will help fallback to a normal HTML file input for browsers not supporting JQuery or Javascript.
The file input consists of the following three sections with options and templates to control the display:
file caption section: to display a brief information of the file(s) selected
file action buttons section: to browse, remove, and upload files.
file preview section: to display the selected files on client for preview (supports preview of image, text, flash, and video file types). Other file types will be displayed as normal thumbnails.
The plugin automatically converts an input with type = file to an advanced file picker input
if you set its class = file. All options to the input can be passed as HTML5
data attributes.
Ability to select and preview multiple files. Uses HTML 5 File reader API to read and preview files. Displays the progress of files being being loaded onto the preview zone, in case many files are chosen.
Offers predefined templates and CSS classes which can be changed to style your file-input display as per your needs.
With v1.5.0, you can now configure the plugin to show an initial preview of
images/files with initial caption
(more useful for record update scenarios). Refer the initialPreview
and initialCaption
properties in the plugin options
section for configuring this.
Option to show/hide any or all of the following:
caption section
preview section
upload button
remove button
Customise the location of the target container elements to display the entire plugin, the caption container, the caption text, the preview container, preview image, and preview status.
For text file previews, autowrap the text to the thumbnail width, and show a wrap indicator link to display complete text on hover. You can customize the wrap indicator (which defaults to …).
Customise the messages for preview, progress, and files selected.
Upload action defaults to form submit. Supports an upload route/server action parameter for custom ajax based upload.
Triggers JQuery events for advanced development. Events currently available are filereset,
fileclear, filecleared, fileloaded, and fileerror.
Disabled and readonly file input support.
Dynamically auto size the file captions for long file names exceeding container width.
Raise new fileimageuploaded event that fires after image is completely loaded on the preview
container.
Autosize preview images when they exceed the size of the preview container.
Completely templatized and extensible to allow configuration of the file-input the way the developer wants.
Preview intelligence based on various file preview types. The inbuilt file support types are categorized
as
image, text, html, video, audio, flash,
object, and other.
allowedPreviewTypes: You can now configure which all file types are allowed to be shown as
a preview. This defaults to ['image', 'html', 'text', 'video', 'audio', 'flash', 'object'].
Thus all file types are treated as an object to preview by default. For exampleTo preview only image
and video, you can set this to ['image', 'video']. To disable content preview for all file-types and show the previewIcon instead as a thumbnail, set this to null, empty, or false.
allowedPreviewMimeTypes: In addition to allowedPreviewTypes, you can also
control which all mime types can be displayed for preview. This defaults to null,
meaning all mime types are supported.
>NOTE: With release 2.5.0 you can now control which file types or extensions are allowed for upload
by setting allowedFileTypes and allowedFileExtensions.
layoutTemplates: Allows you to configure all layout template settings within one property.
The layout objects that can be configured are: main1, main2,
preview, caption, and modal.
previewTemplates: All preview templates for each preview type have been
combined into one property, instead of separate templates for image, text etc.
The keys are the formats as set in allowedPreviewTypes and values are the templates used
for previewing. There are default prebuilt templates for each
preview file type (generic, image, text, html,
video, audio, flash, object, and other).
The generic template is used only for displaying
initialPreview content using direct markup.
previewSettings: Allows you to configure width and height for each preview image type. The
plugin has default widths and heights predefined for each type i.e
image, text, html, video, audio, flash,
and object.
fileTypeSettings: Allows you to configure and identify each preview file type using a
callback. The plugin has default callbacks predefined to identify each type i.e
image, text, html, video, audio, flash,
and object.
Replacing tags within templates has been enhanced. With this release it will automatically check for multiple occurrences of each tag to replace within a template string.
Manipulate events and add your own custom validation messages easily by returning output to abort uploads in any of the other events.
Support for translations and locales.
Flash preview will require Shockwave flash to be installed and supported by the client browser. The flash
preview currently works successfully with webkit browsers only. Video & Audio formats are however
supported by all modern browsers that support the HTML5 video/audio tags. Note
that browsers have limited number of video/audio formats supported by the HTML5 video element (e.g. mp4,
webm, ogg, mp3, wav). The size of video files are recommended to be small (to be controlled through maxFileSize
property) so that it does not affect the preview performance. You can copy a few files from the examples
directory of this plugin repo, to test a few examples of flash and video files.
With release 4.0.0, the plugin now also includes inbuilt support for AJAX Uploads and selectively adding or deleting files. AJAX upload functionality are built upon HTML5 FormData and XMLHttpRequest Level 2 standards. Most modern browsers do support this standard, but the plugin will automatically degrade to normal form based submission for unsupported browsers.
Add functionality for AJAX based UPLOAD using HTML5 FormData (most modern browsers support it). Will degrade to normal Form Based File submission if this is not supported.
To use AJAX Upload, one must set the uploadUrl property.
Enhance plugin to now allow files to be added, appended, removed (based on FEEDBACK from many). Thus one can append files to preview.
New DRAG & DROP zone available in preview to drag and drop files and append.
Delete or upload files one by one OR in batch.
If showPreview is set to false, or uploadUrl is not supported plugin will degrade to normal
form based upload.
Configurable indicators for file awaiting upload, file successfully uploaded, files errored in upload.
Ability to add extra form data with ajax based uploads.
Upload progress bar and individual thumbnail upload indicators.
Ability to cancel and abort ongoing AJAX uploads.
Build up initial preview content (e.g. gallery of saved images). You can set initial preview actions (prebuilt support for initial preview delete). Other custom action buttons can be set for initial preview thumbnails as well.
Ensure plugin is still lean in size and optimized for performance inspite of the above features by optimally utilizing HTML5 & jquery features only.
Automatically refresh preview with content from server as soon as an ajax upload finishes.
The plugin can be installed automatically or manually using one of these options:
$ bower install bootstrap-fileinput
composer package manager. Either run
$ php composer.phar require kartik-v/bootstrap-fileinput "dev-master"
or add:
"kartik-v/bootstrap-fileinput": "dev-master"
to your composer.json file
You can also manually install the plugin easily to your project. Just download the source ZIP or TAR ball and extract the plugin assets (css and js folders) into your project.
/fileinput_locale_<lang>.js after the core fileinput.min.js file, where <lang>
is the language code (e.g. de, fr etc.). If locale file does not exist, you can submit a
translation for the new language via a new
pull request to add to this folder. Check the sample locale
file to copy and create a translation configuration for your own language.
Bootstrap 3.x. However, the plugin can be customized for any CSS framework using templates.
Latest JQuery
Most modern browsers supporting HTML5 file inputs and FileReader API including CSS3 & JQuery.
For file previews to work, the browser must support the HTML5 FileReaderAPI - else the plugin will auto-degrade to a normal file input. For Internet Explorer, one must use IE versions 10 and above. IE9 and below will work as a normal file input, and will not support multiple file selection or the HTML 5 FileReader API.
With release 4.0, AJAX uploads are supported. AJAX uploads require that the browser support HTML5 FormData and XHR2 (XMLHttpRequest 2). Most modern browsers support FormData and XHR2. The plugin will automatically degrade to normal form based submission for browsers not supporting AJAX uploads.
The plugin uses HTML 5 features to achieve various functionalities. Most modern browsers support these features. However, to know if your browser supports these functions you must run through these checks once below.
| Functionality | Description | Support |
|---|---|---|
| File Input Multiple | Allow users to select multiple files using the native HTML file input. | Browsers |
| HTML 5 File API | Allow reading and previewing files on the preview pane using the plugin | Browsers |
| HTML 5 XHR2 & FormData | Allow using ajax uploads with ability to append / delete files and track using a progress bar. | Browsers |
| HTML5 Drag Drop | Ability to drag and drop files into a dropzone (enabled only for ajax uploads with HTML5 XHR2). | Browsers |
Largely speaking, the plugin can be configured in one of the following two different modes for upload. IMPORTANT: Do not try to combine the modes below to receive file data as you will receive inconsistent and/or erroneous output.
Form Submission: In this mode, you do not set the uploadUrl property. The plugin will
use the native file input to store files and it can be read after a normal FORM submission (you
must envelop the input within a FORM). This is useful for single file uploads OR simpler scenarios of
multiple file uploads. Configuration is straightforward as you can read all data POSTED from a native
form submission. However, note that the native file input is read only and cannot be modified or
updated by external code. Especially for multiple file input selections, ONE cannot append files to an
already selected file list. If one tries to select files on an already selected file input, it will
overwrite and clear the previous selection. Similarly, one cannot selectively remove/delete files that have been
added before upload in this mode.
Ajax Submission: In this mode, you MUST SET the uploadUrl property to a VALID ajax
processing server action/URL. If the uploadUrl is set, then the plugin automatically
assumes an ajax upload for the scenario. The plugin offers advanced features for ajax submission that is
not available in form submission. Features like drag and drop of files, appending/removing files in
preview zone, getting a progress bar for your uploads are all possible ONLY IN THIS mode. Your browser
must support HTML5 FormData/XHR2 for this to work and your server code that processes the ajax call must
return a valid JSON response.
uploadExtraData is sent with the ajax response. The events filebatchpreupload,
filebatchuploadsuccess, filebatchuploadcomplete, or
filebatchuploaderror will be triggered in this case. It will not have any data for the
files selected, but will allow the extra data to be sent.
| Functionality / Requirement | Form Submission | Ajax Submission |
|---|---|---|
| Support single & multiple file upload | ||
| Preview files using HTML 5 FileAPI | ||
| Read files directly via form submission | ||
| Individual file delete icon for each preview thumbnail | 1 | 2 |
| Individual file upload icon for each preview thumbnail | ||
| Requires valid JSON response back from server | ||
| Requires browser support for HTML5 FormData/XHR2 | ||
| Server code to process ajax and send JSON Response | ||
| Drag & Drop Files using drop zone | ||
| Ability to append files to already selected list | ||
| Ability to delete files to already selected list | 1 | |
| Progress bar for uploads | ||
| Read additional form data | Directly via form submit |
Via
uploadExtraData |
1 - Via initialPreviewConfig (for server uploaded files only).
2 - For both server uploaded files (via initialPreviewConfig) and client selected
files at runtime.
[input type="file"] to a file input control, if you
attach a css class file to the input. But, if you are initializing the plugin separately via javascript, then
DO NOT ATTACH the css class file to the input (as it will result in duplicate initializations and the javascript
code maybe skipped).
Step 1: Load the following assets in your header.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
<link href="path/to/css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="path/to/js/fileinput.min.js" type="text/javascript"></script>
<!-- bootstrap.js below is only needed if you wish to use the feature of viewing details
of text file preview via modal dialog -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" type="text/javascript"></script>
<!-- optionally if you need translation for your language then include
locale file as mentioned below -->
<script src="path/to/js/fileinput_locale_<lang>.js"></script>
If you noticed, you need to load the jquery.min.js and bootstrap.min.css in addition to
the fileinput.min.css and fileinput.min.js. The locale file fileinput_locale_<lang>.js
can be optionally included for translating for your language if needed.
Step 2a: Initialize the plugin on your page. For example,
// initialize with defaults
$("#input-id").fileinput();
// with plugin options
$("#input-id").fileinput({'showUpload':false, 'previewFileType':'any'});
The #input-id is the identifier for the input (e.g. type=file) on your page, which is
hidden automatically by the plugin.
Step 2b: Alternatively, you can directly set the plugin options to any input, through HTML 5 data attributes to your input field.
<input id="input-id" type="file" class="file" data-preview-file-type="text">
You need to setup the server methods to parse and return the right response via AJAX. You can setup uploads in asynchronous OR synchronous modes as described below.
This is the default mode, whereby the uploadAsync property is set to true. When uploading multiple files, the asynchronous mode allows triggering parallel server calls for each file upload. You can control the maximum number of files allowed at a time to be uploaded by setting the maxFileCount property. In asynchronous mode, progress of each thumbnail in the preview is validated and updated.
Your server method as set in uploadUrl receives the following data from the plugin
file data: This data is sent to the server in a format very similar to the form file input. For example in PHP you can read this data as $_FILES['input-name'], where input-name is the name attribute of your input. If you do not set a name attribute for your input, the name is defaulted to file_data. Note that multiple file uploads require that you set multiple property to true for your input. So in PHP you would receive the file data as $_FILES['file_data']
extra data: The plugin can send additional data to your server method. This can be done by setting uploadExtraData as an associative array object in key value pairs. So if you have setup uploadExtraData={id:'kv-1'}, in PHP you can read this data as $_POST['id'].
Your server method as set in uploadUrl must send data back as a json encoded object. In this case you can send these 4 pieces of information. Note that in asynchronous mode, you will ALWAYS receive ONE FILE record from the server - so adjust your code accordingly.
error: string, which will be the error message for the entire batch upload and will help the plugin to identify error in the file upload. For example the response from server would be sent as {error: 'You are not allowed to upload such a file.'}. Note: The plugin will automatically validate and display ajax exception errors.
initialPreview: array, the list of image files or any HTML markup to point to your uploaded files. You will always send ONE row in this array - because you will always receive ONE file with the upload in asynchronous mode. If this property is set, the plugin will automatically replace the files dynamically in the preview content after upload success. The configuration for this is similar to the initialPreview option setting. For example:
initialPreview: [
'<img src='/images/desert.jpg' class='file-preview-image' alt='Desert' title='Desert'>',
],
initialPreviewConfig: array, the configuration to identify properties for each file markup in initialPreview item (that is setup as part of initialPreview). You will always send ONE row in this array - because you will always receive ONE file with the upload in asynchronous mode. If this property is set, the plugin will automatically replace the files dynamically in the preview content after upload success. The configuration for this is similar to the initialPreviewConfig option setting. For example:
initialPreviewConfig: [
{
caption: 'desert.jpg',
width: '120px',
url: 'http://localhost/avatar/delete', // server delete action
key: 100,
extra: {id: 100}
}
]
initialPreviewThumbTags: array, an array of objects corresponding to replacing tags within each initial preview thumbnail. The initial preview thumbnails set via initialPreview will read this configuration for replacing tags.
// change thumbnail footer template
// set initial preview template tags
initialPreviewThumbTags:[
{
'{CUSTOM_TAG_NEW}': ' ',
'{CUSTOM_TAG_INIT}': 'lt;span class=\'custom-css\'>CUSTOM MARKUPlt;/span>'
}
];
append: boolean, whether to append the content to the initialPreview if you already set an initialPreview on INIT. If not set this defaults to true. If set to false, the plugin will overwrite the initialPreview content.
IMPORTANT
You MUST send a valid JSON response from your server, else the upload process will fail. Even if you do not encounter any error, you must at least send an empty JSON object {} from your server.
To trap and display a validation error, your JSON response data must include the error key, whose value will be the error HTML markup to display. This is to be setup as mentioned above.
You can also send in additional keys or data with your JSON response, for you to process them for advanced cases using events like fileuploaded.
In this mode, the uploadAsync property is set to false. This will trigger just one batch upload call to the server and send files from client to server as an array object. Even in this mode, you can control the maximum number of files allowed at a time to be uploaded by setting the maxFileCount property. However, in synchronous mode, progress will be only at a overall level. Progress of each thumbnail in the preview is not exactly validated and updated. However, the plugin offers you a method of identifying upload errors faced for each file.
Your server method as set in uploadUrl receives the following data from the plugin
file data: This data is sent to the server in a format very similar to the form file input. For example in PHP you can read this data as $_FILES['input-name'], where input-name is the name attribute of your input. Also as in asynchronous mode before, if you do not set a name attribute for your input, the name is defaulted to file_data. You must set your input name as an array format as mentioned in this web tip, in addition to setting multiple property to true. If you do not set your input name as an array format, you would receive only the first file on your server. In PHP you would receive the file data as $_FILES['input-name'], which will be an array of file objects.
extra data: The plugin can send additional data to your server method. This can be done by setting uploadExtraData as an associative array object in key value pairs. So if you have setup uploadExtraData={id:'kv-1'}, in PHP you can read this data as $_POST['id'].
In synchronous mode as well, the uploadUrl must send data back as a json encoded object. In this case you send these 5 pieces of information.
error: string, which will be the error message for the entire batch upload and will help the plugin to identify error in the file upload.
errorkeys: array, the keys (zero-based indexes for the file data received) for the files that have errored out. Based on this data, the plugin will automatically set the thumbnails and each individual preview file to error out.
initialPreview: array, the list of image files or any HTML markup to point to your uploaded files. If this property is set, the plugin will automatically replace the files dynamically in the preview content after upload success. The configuration for this is similar to the initialPreview option setting. For example:
initialPreview: [
'<img src='/images/desert.jpg' class='file-preview-image' alt='Desert' title='Desert'>',
'<img src='/images/jellyfish.jpg' class='file-preview-image' alt='Jelly Fish' title='Jelly Fish'>',
],
initialPreviewConfig: array, the configuration to identify properties for each file markup in initialPreview item (that is setup as part of initialPreview). If this property is set, the plugin will automatically replace the files dynamically in the preview content after upload success. The configuration for this is similar to the initialPreviewConfig option setting. For example:
initialPreviewConfig: [
{
caption: 'desert.jpg',
width: '120px',
url: 'http://localhost/avatar/delete', // server delete action
key: 100,
extra: {id: 100}
},
{
caption: 'jellyfish.jpg',
width: '120px',
url: 'http://localhost/avatar/delete', // server delete action
key: 101,
extra: function() {
return {id: $('#id').val()};
},
}
]
initialPreviewThumbTags: array, an array of objects corresponding to replacing tags within each initial preview thumbnail. The initial preview thumbnails set via initialPreview will read this configuration for replacing tags.
// change thumbnail footer template
// set initial preview template tags
initialPreviewThumbTags:[
{
'{CUSTOM_TAG_NEW}': ' ',
'{CUSTOM_TAG_INIT}': 'lt;span class=\'custom-css\'>CUSTOM MARKUP 1lt;/span>'
},
{
'{CUSTOM_TAG_NEW}': ' ',
'{CUSTOM_TAG_INIT}': 'lt;span class=\'custom-css\'>CUSTOM MARKUP 2lt;/span>'
}
];
append: boolean, whether to append the content to the initialPreview if you already set an initialPreview on INIT. If not set this defaults to true. If set to false, the plugin will overwrite the initialPreview content.
For example the response from server would be sent as {error: 'You have faced errors in 4 files.', errorkeys: [0, 3, 4, 5]}. Note: The plugin will automatically validate and display ajax exception errors.
IMPORTANT
You MUST send a valid JSON response from your server, else the upload process will fail. Even if you do not encounter any error, you must at least send an empty JSON object {} from your server.
To trap and display a validation error, your JSON response data must include the error key, whose value will be the error HTML markup to display. In addition, you must typically also send the errorkeys for synchronous mode to identify the keys for files which faced errors. This is to be setup as mentioned above.
You can also send in additional keys or data with your JSON response, for you to process them for advanced cases using events like filebatchuploadsuccess.
The plugin supports these following options:
string language configuration for the plugin to enable the plugin to display messages for your locale (you
must set the ISO code for the language). You can have multiple language widgets on the same page. The locale JS file
for the language code must be defined as mentioned in the translations section. The file must be loaded after fileinput.js.
boolean whether to display the file caption. Defaults to true.
boolean whether to display the file preview. Defaults to true.
boolean whether to display the file remove/clear button. Defaults to true.
boolean whether to display the file upload button. Defaults to true. This will default to a
form submit button, unless the uploadUrl is specified.
boolean whether to display the file upload cancel button. Defaults to true. This will be only
enabled and displayed when an AJAX upload is in process.
boolean whether to persist display of the uploaded file thumbnails in the preview window (for ajax uploads)
until the remove/clear button is pressed. Defaults to true. When set to false, a next
batch of files selected for upload will clear these thumbnails from preview.
boolean whether to automatically replace the files in the preview after the maxFileCount limit is reached and a new set of file(s) is/are selected. This will only work if a valid maxFileCount is set. Defaults to false.
string any additional CSS class to append to the caption container.
string any additional CSS class to append to the preview container.
string any additional CSS class to append to the main plugin container.
string | array the initial preview content to be displayed. You can pass the minimal HTML markup for
displaying your image, text, or file.
If set as a string, this will display a single file in the initial preview if there is no delimiter. You can set a
delimiter (as defined
in initialDelimiter) to show multiple files in initial preview. If set as an array, it will display all
files in the array as an
initial preview (useful for multiple file upload scenarios).
The following CSS classes will need to be added for displaying each file type as per the plugin style theme:
file-preview-image
file-preview-text
file-preview-other
Examples of how you can setup various files for initial preview:
// for image files
initialPreview: [
"<img src='/images/desert.jpg' class='file-preview-image' alt='Desert' title='Desert'>",
"<img src='/images/jellyfish.jpg' class='file-preview-image' alt='Jelly Fish' title='Jelly Fish'>",
],
// for text files
initialPreview: "<div class='file-preview-text' title='NOTES.txt'>" +
"This is the sample text file content upto wrapTextLength of 250 characters" +
"<span class='wrap-indicator' onclick='$(\"#show-detailed-text\").modal(\"show\")' title='NOTES.txt'>[…]</span>" +
"</div>"
// for other files
initialPreview: "<div class='file-preview-text'>" +
"<h2><i class='glyphicon glyphicon-file'></i></h2>" +
"Filename.xlsx" + "</div>"
int, the count of initial preview items that will be added to the count of files selected in preview. This
is applicable when displaying
the right caption, when overwriteInitial is set to false.
string, the delimiter to be used for splitting the initial preview content as individual file thumbnails
(applicable only if initialPreview is passed as a string instead of array). Defaults
to *$$*.
array, the configuration for setting up important properties for each initialPreview item (that
is setup as part of initialPreview). Each element in the array should be an object/associative array
consisting of the following keys:
caption: string, the caption or filename to display for each initial preview item
content.
width: string, the CSS width of the image/content displayed.
url: string, the URL for deleting the image/content in the initial preview via AJAX
post response. This will default to deleteUrl if not set.
key: string | object, the key that will be passed as data to the url via AJAX POST.
frameClass: string, the additional frame css class to set for the file's thumbnail frame.
frameAttr: object, the HTML attribute settings (set as key:value pairs) for the thumbnail frame.
extra: object | function, the extra data that will be passed as data to the initial
preview delete url/AJAX server call via POST. This will default to deleteExtraData if not set.
An example configuration of initialPreviewConfig (for the previously set
initialPreviewContent) can be:
// setup initial preview with data keys
initialPreview: [
"<img src='/images/desert.jpg' class='file-preview-image' alt='Desert' title='Desert'>",
"<img src='/images/jellyfish.jpg' class='file-preview-image' alt='Jelly Fish' title='Jelly Fish'>",
],
// initial preview configuration
initialPreviewConfig: initialPreviewConfig: [
{
caption: 'desert.jpg',
width: '120px',
url: '/localhost/avatar/delete',
key: 100,
extra: {id: 100}
},
{
caption: 'jellyfish.jpg',
width: '120px',
url: '/localhost/avatar/delete',
key: 101,
frameClass: 'my-custom-frame-css',
frameAttr: {
style: 'height:80px',
title: 'My Custom Title',
},
extra: function() {
return {id: $("#id").val()};
},
}
]
The ajax delete action will send the following data to server via POST:
key: the key setting as setup in initialPreviewConfig['key']
extra: the extra data passed either via initialPreviewConfig['extra'] OR deleteExtraData
if former is not set.
bool, whether the delete button will be displayed for each thumbnail that has been created with initialPreview.
array, this will be a list of tags used in thumbnail templates that will be replaced dynamically within the thumbnail markup, when the thumbnail is rendered. For example:
// change thumbnail footer template
layoutTemplates.footer = 'lt;div class="file-thumbnail-footer">\n' +
' lt;div class="file-caption-name">{caption}lt;/div>\n' +
' {CUSTOM_TAG_NEW}\n' +
' {CUSTOM_TAG_INIT}\n' +
' {actions}\n' +
'lt;/div>';
// set preview template tags
previewThumbTags = {
'{CUSTOM_TAG_NEW}': 'lt;span class="custom-css">CUSTOM MARKUPlt;/span>',
'{CUSTOM_TAG_INIT}': ' '
};
array, this is an extension of previewThumbTags specifically for initial preview content - but
will be configured as an array of objects corresponding to each initial preview thumbnail. The initial preview
thumbnails set via initialPreview will read this configuration for replacing tags. Extending example
above:
// change thumbnail footer template
layoutTemplates.footer = 'lt;div class="file-thumbnail-footer">\n' +
' lt;div class="file-caption-name">{caption}lt;/div>\n' +
' {CUSTOM_TAG_NEW}\n' +
' {CUSTOM_TAG_INIT}\n' +
' {actions}\n' +
'lt;/div>';
// setup initial preview with data keys
initialPreview: [
"lt;img src='/images/desert.jpg' class='file-preview-image' alt='Desert' title='Desert'>",
"lt;img src='/images/jellyfish.jpg' class='file-preview-image' alt='Jelly Fish' title='Jelly Fish'>",
],
// set initial preview template tags
initialPreviewThumbTags = {
'{CUSTOM_TAG_NEW}': ' ',
'{CUSTOM_TAG_INIT}': 'lt;span class="custom-css">CUSTOM MARKUPlt;/span>'
};
object | function the extra data that will be passed as data to the initial preview delete url/AJAX server
call via POST. This will be overridden by the initialPreviewConfig['extra'] property. This property is
only applicable for ajax deletions in initial preview and when you have set a value for initialPreviewConfig['url']
or deleteUrl.
This can be setup either as an object (associative array of keys and values) or as a function callback. As an object, it can be set for example as:
{id: 100, value: '100 Details'}
As a function callback, it can be setup for example as:
function() {
var obj = {};
$('.your-form-class').find('input').each(function() {
var id = $(this).attr('id'), val = $(this).val();
obj[id] = val;
});
return obj;
}
The ajax delete action will send the following data to server via POST:
key: the key setting as setup in initialPreviewConfig['key']
key: value pairs either via
initialPreviewConfig['extra'] OR deleteExtraData if former is not set.string, the URL for deleting the image/content in the initial preview via AJAX post response. This will be
overridden by the initialPreviewConfig['url'] property.
The ajax delete action will send the following data to server via POST:
key: the key setting as setup in initialPreviewConfig['key']
key: value pairs either via
initialPreviewConfig['extra'] OR deleteExtraData if former is not set.string the initial preview caption text to be displayed. If you do not set a value here and initialPreview
is set to
true this will default to "{preview-file-count} files selected", where {preview-file-count}
is the count of the
files passed in initialPreview.
boolean whether you wish to overwrite the initial preview content and caption setup. This defaults to true,
whereby, any initialPreview content set
will be overwritten, when new file is uploaded or when files are cleared. Setting it to false will help
displaying a saved image or file from database always -
useful especially when using the multiple file upload feature.
object the templates configuration for rendering each part of the layout. You can set the following templates to control the widget layout:
main1: the template for rendering the widget with caption.
main2: the template for rendering the widget without caption.
preview: the template for rendering the preview.
icon: the icon to render before the caption text.
caption: the template for rendering the caption.
modal: the template for rendering the modal (for text file preview zooming).
progress: the template for the progress bar when upload is in progress (for batch/mass
uploads). The following tags will be parsed and replaced automatically:
{percent}: will be replaced with the upload progress percentage.
footer: the template for the footer section of each file preview thumbnail. The following tags
will be parsed and replaced automatically:
{actions}: will be replaced with the output of the actions template.
actions: the template for the file action buttons to be displayed within the thumbnail footer.
The following tags will be parsed and replaced automatically:
{upload}: will be replaced with the output of the actionUpload template.
{delete}: will be replaced with the output of the actionDelete template.
actionDelete: the template for the file delete action button within the thumbnail
footer. The following tags will be parsed and replaced automatically:
{removeClass}: the css class for the remove button. Will be replaced with the removeClass
set within fileActionSettings.
{removeIcon}: the icon for the remove button. Will be replaced with the removeIcon
set within fileActionSettings.
{removeTitle}: the title to display on hover for the remove button. Will be replaced
with the removeTitle set within fileActionSettings.
{dataUrl}: the URL for deleting the file thumbnail for initialPreview
content only. Will be replaced with the url set within
initialPreviewConfig.
{dataKey}: the key (additional data) that will be passed to the URL above via POST to
the AJAX call. Will be replaced with the key set within
initialPreviewConfig.
actionUpload: the template for the file upload action button within the thumbnail
footer.
{uploadClass}: the css class for the upload button. Will be replaced with the uploadClass
set within fileActionSettings.
{uploadIcon}: the icon for the upload button. Will be replaced with the uploadIcon
set within fileActionSettings.
{uploadTitle}: the title to display on hover for the upload button. Will be replaced
with the uploadTitle set within fileActionSettings.
The main1 and main2 templates would automatically parse the following tags for replacement:
{class}: the CSS class as set in the mainClass property.
{preview}: the content parsed by the previewTemplate and will be displayed only if
showPreview is true.
{caption}: the content parsed by the captionTemplate and will be displayed only if
showCaption is true.
{remove}: the file remove/clear button and will be displayed only if showRemove is
true.
{upload}: the file upload button and will be displayed only if showUpload is
true.
{cancel}: the file upload cancel button that will be displayed when AJAX upload is in process
to abort the AJAX upload.
{browse}: the main file browse button to select your files for input.
The progress template would automatically parse the following tags for replacement:
{class}: the CSS class as set in the progressClass or
progressCompleteClass property (depending on the progress percentage).
The preview and caption templates can understand the following special tags which will be
replaced:
{class}: the CSS class as set in the mainClass, captionClass or
previewClass properties.
The layoutTemplates if not set will default to:
{
main1: '{preview}\n' +
'<div class="kv-upload-progress hide"></div>\n' +
'<div class="input-group {class}">\n' +
' {caption}\n' +
' <div class="input-group-btn">\n' +
' {remove}\n' +
' {cancel}\n' +
' {upload}\n' +
' {browse}\n' +
' </div>\n' +
'</div>',
main2: '{preview}\n<div class="kv-upload-progress hide"></div>\n{remove}\n{cancel}\n{upload}\n{browse}\n',
preview: '<div class="file-preview {class}">\n' +
' <div class="close fileinput-remove">×</div>\n' +
' <div class="{dropClass}">\n' +
' <div class="file-preview-thumbnails">\n' +
' </div>\n' +
' <div class="clearfix"></div>' +
' <div class="file-preview-status text-center text-success"></div>\n' +
' <div class="kv-fileinput-error"></div>\n' +
' </div>\n' +
'</div>',
icon: '<span class="glyphicon glyphicon-file kv-caption-icon"></span>',
caption: '<div tabindex="-1" class="form-control file-caption {class}">\n' +
' <div class="file-caption-name"></div>\n' +
'</div>',
btnDefault: '<button type="{type}" tabindex="500" title="{title}" class="{css}"{status}>{icon}{label}</button>',
btnLink: '<a href="{href}" tabindex="500" title="{title}" class="{css}"{status}>{icon}{label}</a>',
btnBrowse: '<div tabindex="500" class="{css}"{status}>{icon}{label}</div>',
modal: '<div id="{id}" class="modal fade">\n' +
' <div class="modal-dialog modal-lg">\n' +
' <div class="modal-content">\n' +
' <div class="modal-header">\n' +
' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>\n' +
' <h3 class="modal-title">Detailed Preview <small>{title}</small></h3>\n' +
' </div>\n' +
' <div class="modal-body">\n' +
' <textarea class="form-control" style="font-family:Monaco,Consolas,monospace; height: {height}px;" readonly>{body}</textarea>\n' +
' </div>\n' +
' </div>\n' +
' </div>\n' +
'</div>',
zoom: '<button type="button" class="btn btn-default btn-sm btn-block" title="{zoomTitle}: {caption}" onclick="{dialog}">\n' +
' {zoomInd}\n' +
'</button>\n',
progress: '<div class="progress">\n' +
' <div class="progress-bar progress-bar-success progress-bar-striped text-center" role="progressbar" aria-valuenow="{percent}" aria-valuemin="0" aria-valuemax="100" style="width:{percent}%;">\n' +
' {percent}%\n' +
' </div>\n' +
'</div>',
footer: '<div class="file-thumbnail-footer">\n' +
' <div class="file-caption-name" style="width:{width}">{caption}</div>\n' +
' {actions}\n' +
'</div>',
actions: '<div class="file-actions">\n' +
' <div class="file-footer-buttons">\n' +
' {upload}{delete}' +
' </div>\n' +
' <div class="file-upload-indicator" tabindex="-1" title="{indicatorTitle}">{indicator}</div>\n' +
' <div class="clearfix"></div>\n' +
'</div>',
actionDelete: '<button type="button" class="kv-file-remove {removeClass}" title="{removeTitle}"{dataUrl}{dataKey}>{removeIcon}</button>\n',
actionUpload: '<button type="button" class="kv-file-upload {uploadClass}" title="{uploadTitle}">{uploadIcon}</button>\n'
}
The following templates will be used in rendering the main buttons for upload, remove, cancel, and browse.
btnDefault: The template for upload, remove, and cancel buttons.
btnLink: The template for upload button when used with ajax (i.e. when uploadUrl is set).
btnBrowse: The template for the browse button.
The following tags will be parsed and auto replaced in the above button templates:
{type}: the HTML button type, defaults to button for most buttons and submit for form based uploads.
{title}: the title to display on button hover.
{css}: the CSS class for the button. This is derived from settings for uploadClass or removeClass or cancelClass or browseClass.
{status}: the disabled status for the button if available (else will be blank).
{icon}: the button icon as identified by uploadIcon or removeIcon or cancelIcon or browseIcon.
{label}: the button label as identified by uploadLabel or removeLabel or cancelLabel or browseLabel.
{href}: applicable only for Upload button for ajax uploads and will be replaced with the uploadUrl property.
object the templates configuration for rendering each preview file type. The following file types are recognized:
image: the preview template for image files.
text: the preview template for text files.
html: the preview template for html files.
video: the preview template for video files (supported by HTML 5 video tag).
audio: the preview template for audio files (supported by HTML 5 audio tag).
flash: the preview template for flash files (supported currently on webkit browsers).
object: the preview template for all other files - by default treated as object. To disable this
behavior, configure the allowedPreviewTypes property.
generic: this template is used ONLY for rendering the initialPreview markup content
passed directly as a raw format.
The following tags will be parsed and replaced in each of the templates:
{previewId}: will be replaced with the generated identifier for the preview frame container.
{data}: will be replaced with the data source for each preview type.
{width}: will be replaced with the width for the file type as set in previewSettings.
{height}: will be replaced with the height for the file type as set in previewSettings.
{caption}: will be replaced with the file name.
{type}: will be replaced with the file type.
{content}: this is applicable only for the generic template. It will be replaced with
the raw HTML markup as set in initialPreview. None of
the above tags will be parsed for the generic template.
{dialog}: currently applicable only for text file previews. Will be replaced with the JS code to launch the modal dialog.
{zoomTitle}: currently applicable only for text file previews. This will be replaced with the msgZoomTitle property. This is the title that is displayed on hover of the zoom button (which on clicking will display the text file).
{zoomInd}: currently applicable only for text file previews. This will be replaced with the zoomIndicator property. This is the title that is displayed on hover of the zoom button (which on clicking will display the text file).
{heading}: currently applicable only for text file previews. This represents the modal dialog heading title. This will be replaced with the msgZoomModalHeading property.
As noted, if you are coming from an earlier release (before v2.4.0), all preview templates have now been combined into one property, instead of separate templates for image, text etc.
{
generic: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}">\n' +
' {content}\n' +
' {footer}\n' +
'</div>\n',
html: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}">\n' +
' <object data="{data}" type="{type}" width="{width}" height="{height}">\n' +
' ' + DEFAULT_PREVIEW + '\n' +
' </object>\n' +
' {footer}\n' +
'</div>',
image: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}">\n' +
' <img src="{data}" class="file-preview-image" title="{caption}" alt="{caption}" ' + STYLE_SETTING + '>\n' +
' {footer}\n' +
'</div>\n',
text: '<div class="file-preview-frame{frameClass}" id="{previewId}" data-fileindex="{fileindex}">\n' +
' <pre class="file-preview-text" title="{caption}" ' + STYLE_SETTING + '>{data}</pre>\n' +
' <button type="button" class="btn btn-default btn-sm btn-block" title="{zoomText}: {caption}" onclick="{dialog}">\n' +
' {zoomInd}\n' +
' </button>\n' +
' {footer}\n' +
'</div>',
video: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}" title="{caption}" ' + STYLE_SETTING + '>\n' +
' <video width="{width}" height="{height}" controls>\n' +
' <source src="{data}" type="{type}">\n' +
' ' + DEFAULT_PREVIEW + '\n' +
' </video>\n' +
' {footer}\n' +
'</div>\n',
audio: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}" title="{caption}" ' + STYLE_SETTING + '>\n' +
' <audio controls>\n' +
' <source src="{data}" type="{type}">\n' +
' ' + DEFAULT_PREVIEW + '\n' +
' </audio>\n' +
' {footer}\n' +
'</div>\n',
flash: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}" title="{caption}" ' + STYLE_SETTING + '>\n' +
' <object type="application/x-shockwave-flash" width="{width}" height="{height}" data="{data}">\n' +
OBJECT_PARAMS + ' ' + DEFAULT_PREVIEW + '\n' +
' </object>\n' +
' {footer}\n' +
'</div>\n',
object: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}" title="{caption}" ' + STYLE_SETTING + '>\n' +
' <object data="{data}" type="{type}" width="{width}" height="{height}">\n' +
' <param name="movie" value="{caption}" />\n' +
OBJECT_PARAMS + ' ' + DEFAULT_PREVIEW + '\n' +
' </object>\n' +
' {footer}\n' +
'</div>',
other: '<div class="file-preview-frame{frameClass}" id="{previewId}" data-fileindex="{fileindex}"' +
' title="{caption}" ' + STYLE_SETTING + '>\n' +
' <div class="file-preview-other-frame">\n'+
' ' + DEFAULT_PREVIEW + '\n' +
' </div>\n' +
' <div class="file-preview-other-footer">{footer}</div>\n' +
'</div>'
}
The values of the constants used in the above templates are as follows:
STYLE_SETTING = 'style="width:{width};height:{height};"',
OBJECT_PARAMS = ' <param name="controller" value="true" />\n' +
' <param name="allowFullScreen" value="true" />\n' +
' <param name="allowScriptAccess" value="always" />\n' +
' <param name="autoPlay" value="false" />\n' +
' <param name="autoStart" value="false" />\n'+
' <param name="quality" value="high" />\n',
DEFAULT_PREVIEW = '<div class="file-preview-other">\n' +
' <span class="{previewFileIconClass}">{previewFileIcon}</span>\n' +
'</div>'
where:
{previewFileIcon}: corresponds to the previewFileIcon property.
{previewFileIconClass}: corresponds to the previewFileIconClass property.
array the list of allowed file types for upload. This by default is set to null which means the plugin
supports all file types for upload. If an
invalid file type is found, then a validation error message as set in msgInvalidFileType will be
raised. The following types as set in fileTypeSettings
are available for setup.
['image', 'html', 'text', 'video', 'audio', 'flash', 'object']
array the list of allowed file extensions for upload. This by default is set to null which means the plugin supports all file extensions for upload. If an invalid file extension is found, then a validation error message as set in msgInvalidFileExtension will be raised. An example of setting this could be:
['jpg', 'gif', 'png', 'txt']
You need to be careful in case you are setting both allowedFileTypes and
allowedFileExtensions. In this case, the allowedFileTypes property is validated first
and generally precedes the allowedFileExtensions setting (and the latter validation maybe skipped).
array the list of allowed preview types for your widget. This by default supports all file types for
preview. The plugin by default treats each
file as an object if it does not match any of the previous types. To disable this behavior, you can remove object
from the list of allowedPreviewTypes
OR fine tune it through allowedPreviewMimeTypes.To disable content preview for all file-types and show the previewIcon instead as a thumbnail, set this to null, empty, or false.
This is by default setup as following:
['image', 'html', 'text', 'video', 'audio', 'flash', 'object']
array the list of allowed mime types for preview. This is set to null by default which means all possible
mime types are allowed. This setting works in combination
with allowedPreviewTypes to filter only the needed file types allowed for preview. You can check this
list of allowed mime types
to add to this list if needed.
object the list of additional custom tags that will be replaced in the layout templates. This should
be an associative array object of key: value pairs, where:
key: string, is the tag to be replaced and as a standard is recommended to be enclosed
between braces.
value: string|function, is the value that will replace the tag key above. This can be
setup either as a string or callback function.
// example 1 - tags with value set as string
customLayoutTags: {
'{tagA}': '<span class="label label-default">Tag A</span>',
'{tagB}': 'Tag B',
}
// example 2 - tags with value set as callback
customLayoutTags: {
'{tagC}': function() {
return $("#element-id").val();
}
}
object the list of additional custom tags that will be replaced in the preview templates. This should
be an associative array object of key: value pairs, where:
key: string, is the tag to be replaced and as a standard is recommended to be enclosed
between braces.
value: string|function, is the value that will replace the tag key above. This can be
setup either as a string or callback function.
// example 1 - tags with value set as string
customPreviewTags: {
'{tagA}': '<span class="label label-default">Tag A</span>',
'{tagB}': 'Tag B',
}
// example 2 - tags with value set as callback
customPreviewTags: {
'{tagC}': function() {
return $("#element-id").val();
}
}
object the format settings (width and height) for rendering each preview file type. This is by default setup as following:
{
image: {width: "auto", height: "160px"},
html: {width: "213px", height: "160px"},
text: {width: "160px", height: "136px"},
video: {width: "213px", height: "160px"},
audio: {width: "213px", height: "80px"},
flash: {width: "213px", height: "160px"},
object: {width: "213px", height: "160px"},
other: {width: "160px", height: "160px"}
}
object the settings to validate and identify each file type when a file is selected for upload. This is a list of callbacks, which accepts the file mime type and file name as a parameter. This is by default setup as following:
// vType: is the file mime type
// vName: is the file name
{
image: function(vType, vName) {
return (typeof vType !== "undefined") ? vType.match('image.*') : vName.match(/\.(gif|png|jpe?g)$/i);
},
html: function(vType, vName) {
return (typeof vType !== "undefined") ? vType == 'text/html' : vName.match(/\.(htm|html)$/i);
},
text: function(vType, vName) {
return typeof vType !== "undefined" && vType.match('text.*') || vName.match(/\.(txt|md|csv|nfo|php|ini)$/i);
},
video: function (vType, vName) {
return typeof vType !== "undefined" && vType.match(/\.video\/(ogg|mp4|webm)$/i) || vName.match(/\.(og?|mp4|webm)$/i);
},
audio: function (vType, vName) {
return typeof vType !== "undefined" && vType.match(/\.audio\/(ogg|mp3|wav)$/i) || vName.match(/\.(ogg|mp3|wav)$/i);
},
flash: function (vType, vName) {
return typeof vType !== "undefined" && vType == 'application/x-shockwave-flash' || vName.match(/\.(swf)$/i);
},
object: function (vType, vName) {
return true;
},
other: function (vType, vName) {
return true;
},
}
string the icon to be shown in each preview file thumbnail when an unreadable file type for preview is
detected. Defaults to <i class="glyphicon glyphicon-file"></i> .
string the CSS class to be applied to the preview file icon container. Defaults to file-icon-4x.
object the preview icon markup settings for each file extension (type). You need to set this as key: value pairs, where the key corresponds to a file extension (e.g. doc, docx, xls etc.), and the value corresponds to the markup of the icon to be rendered. If this is not set OR a file extension is not set here, the preview will default to previewFileIcon. Note that displaying the icons instead of file content is controlled via allowedPreviewTypes and allowedPreviewMimeTypes
You can setup previewFileIconSettings as shown below:
previewFileIconSettings: {
'doc': '',
'xls': '',
'ppt': '',
'jpg': '',
'pdf': '',
'zip': '',
}
object the extensions to be auto derived for each file extension (type). This is useful if you want to set the same icon for multiple file extension types. You need to set this as `key: value` pairs, where the key corresponds to a file extension as set in previewFileIconSettings (e.g. doc, docx, xls etc.). The value will be a function callback that accepts the following parameter:
ext, string, the file extension (without the . [dot]) of the file currently selected in the preview.
You can configure the callback to match the set of file extensions (via regex or similar) for each `key` and return a boolean output if the file extension matches.
For example, you can setup `previewFileExtSettings` as shown below:
previewFileExtSettings: {
'doc': function(ext) {
return ext.match(/(doc|docx)$/i);
},
'xls': function(ext) {
return ext.match(/(xls|xlsx)$/i);
},
'ppt': function(ext) {
return ext.match(/(ppt|pptx)$/i);
}
}
string the label to display for the file picker/browse button. Defaults to Browse ….
string the icon to display before the label for the file picker/browse button. Defaults to <i
class="glyphicon glyphicon-folder-open"></i> .
string the CSS class for the file picker/browse button. Defaults to btn btn-primary.
string the label to display for the file remove button. Defaults to Remove.
string the icon to display before the label for the file picker/remove button. Defaults to <i
class="glyphicon glyphicon-trash"></i> .
string the CSS class for the file remove button. Defaults to btn btn-default.
string the title to display on hover for the file remove button. Defaults to Clear selected
files.
string the label to display for the file upload button. Defaults to Upload.
string the icon to display before the label for the file upload button. Defaults to <i
class="glyphicon glyphicon-upload"></i> .
string the CSS class for the file upload button. Defaults to btn btn-default.
string the title to display on hover for the file remove button. Defaults to Upload selected
files.
string the URL for the upload processing action (typically for ajax based processing). Defaults to null.
If this is not set or null, then the upload button action will default to form submission. NOTE: This
is MANDATORY if you want to use advanced features like drag & drop, append/remove files, selectively upload files
via ajax etc. The plugin automatically send $_FILES data to the server with the input `name` attribute
as the key if provided. If input name is not set, the key defaults to file-data.
bool whether the batch upload of multiple files will be asynchronous/in parallel. Defaults to
true.
float the maximum file size for upload in KB. If set to 0, it means size allowed is unlimited.
Defaults to 0.
object | function, the extra data that will be passed as data to the url/AJAX server call via POST. This
property is only applicable for ajax uploads and when you have set a value for uploadUrl.
This can be setup either as an object (associative array of keys and values) or as a function callback. As an object, it can be set for example as:
{id: 100, value: '100 Details'}
As a function callback, the uploadExtraData can be setup as shown below. Note that for uploading individual file via thumbnail, the callback can also receive the thumbnail previewId and index as parameters. These are described below:
previewId: the identifier for the preview file container (only available when uploading each thumbnail file)
index: the zero-based sequential index of the loaded file in the preview list (only available when uploading each thumbnail file)
// previewId and index is only available for individual file upload via the thumbnail
function (previewId, index) {
var obj = {};
$('.your-form-class').find('input').each(function() {
var id = $(this).attr('id'), val = $(this).val();
obj[id] = val;
});
return obj;
}
int, the maximum allowed image width in px if you are uploading image files. Defaults to null which means no limit on image width.
int, the maximum allowed image height in px if you are uploading image files. Defaults to null which means no limit on image height.
int, the minimum allowed image width in px if you are uploading image files. Defaults to null which means no limit on image width.
int, the minimum allowed image height in px if you are uploading image files. Defaults to null which means no limit on image height.
int the minimum number of files allowed for each multiple upload. If set to 0, it means number
of files are optional. Defaults to 0.
int the maximum number of files allowed for each multiple upload. If set to 0, it means number
of files allowed is unlimited. Defaults to 0.
boolean, whether to include initial preview file count (server uploaded files) in validating minFileCount and maxFileCount. Defaults to false.
string the title displayed (before the file name) on hover of the zoom button for zooming the file content in a modal window. This is currently applicable only for text file previews. Defaults to View details.
string the heading of the modal dialog that displays the zoomed file content. This is currently applicable only for text file previews. Defaults to Detailed Preview.
string the message to be displayed when the file size exceeds maximum size. Defaults to:
File "{name}" ({size} KB) exceeds maximum allowed upload size of {maxSize} KB. Please retry your upload!
where:
{name}: will be replaced by the file name being uploaded
{size}: will be replaced by the uploaded file size
{maxSize}: will be replaced by the maxFileSize parameter.
string message to be displayed when the file count is less than the minimum count as set in minFileCount.
Defaults to:
You must select at least {n} {files} to upload. Please retry your upload!
where:
{n}: will be replaced by the allowed minimum files as set in minFileCount.
{files}: will be replaced with fileSingle or filePlural properties in
locale file depending on the minFileCount.
string the message to be displayed when the file count exceeds maximum count as set in
maxFileCount. Defaults to:
Number of files selected for upload ({n}) exceeds maximum allowed limit of {m}. Please retry your upload!
where:
{n}: will be replaced by number of files selected for upload
{m}: will be replaced by the allowed maximum files as set in maxFileCount
string the exception message to be displayed when the file selected is not found by the FileReader. Defaults to:
File "{name}" not found!
where:
{name}: will be replaced by the file name being uploaded
string the exception message to be displayed when the file selected is not allowed to be accessed due to a security exception. Defaults to:
Security restrictions prevent reading the file "{name}".
where:
{name}: will be replaced by the file name being uploaded
string the exception message to be displayed when the file selected is not readable by the FileReader API. Defaults to:
File "{name}" is not readable.
where:
{name}: will be replaced by the file name being uploaded
string the exception message to be displayed when the file preview upload is aborted. Defaults to:
File preview aborted for "{name}".
where:
{name}: will be replaced by the file name being uploaded
string the exception message to be displayed for any other error when previewing the file. Defaults to:
An error occurred while reading the file "{name}".
where:
{name}: will be replaced by the file name being uploaded
string the message to be displayed when the file type is not in one of the file types set in allowedFileTypes.
Defaults to:
Invalid type for file "{name}". Only "{types}" files are supported.
where:
{name}: will be replaced by the file name being uploaded
{types}: will be replaced by the comma separated list of types defined in
allowedFileTypes.
string the message to be displayed when the file type is not in one of the file extensions set in allowedFileExtensions.
Defaults to:
Invalid extension for file "{name}". Only "{extensions}" files are supported.
where:
{name}: will be replaced by the file name being uploaded
{extensions}: will be replaced by the comma separated list of extensions defined in allowedFileExtensions.
string the exception message to be displayed within the caption container (instead of
msgFilesSelected),
when a validation error is encountered. Defaults to File Upload Error.
string the css class for the validation error message displayed in the caption container. Defaults to text-danger.
string the icon to be displayed before the validation error in the caption container. Defaults to <i
class="glyphicon glyphicon-exclamation-sign"></i>
string the css class for the error message to be displayed in the preview window when the file size exceeds
maxSize. Defaults to file-error-message.
string the message displayed when the files are getting read and loaded for preview. Defaults to
Loading file {index} of {files} …
The following special variables will be replaced:
{index}: the sequence number of the current file being loaded.
{files}: the total number of files selected for upload.
string the progress message displayed as each file is loaded for preview. Defaults to:
Loading file {index} of {files} - {name} - {percent}% completed.
The following variables will be replaced:
{index}: the sequence number of the current file being loaded.
{files}: the total number of files selected for upload.
{percent}: the percentage of file read and loaded.
{name}: the name of the current file being loaded.
string the progress message displayed in caption window when multiple (more than one) files are selected.
Defaults to {n} files selected. The following variables will be replaced:
{n}: the number of files selected.
string the message displayed when a folder has been dragged to the drop zone. Defaults to Drag & drop
files only! {n} folder(s) dropped were skipped.. The following variables will be replaced:
{n}: the number of folders dropped.
string, the exception message to be displayed when the file selected for preview is an image and its width is less than the minImageWidth setting. Defaults to:
Width of image file "{name}" must be at least {size} px.
where:
{name}: will be replaced by the file name being uploaded.
{size}: will be replaced by the minImageWidth setting.
string, the exception message to be displayed when the file selected for preview is an image and its height is less than the minImageHeight setting. Defaults to:
Height of image file "{name}" must be at least {size} px.
where:
{name}: will be replaced by the file name being uploaded.
{size}: will be replaced by the minImageHeight setting.
string, the exception message to be displayed when the file selected for preview is an image and its width exceeds the maxImageWidth setting. Defaults to:
Width of image file "{name}" cannot exceed {size} px.
where:
{name}: will be replaced by the file name being uploaded.
{size}: will be replaced by the maxImageWidth setting.
string, the exception message to be displayed when the file selected for preview is an image and its height exceeds the maxImageHeight setting. Defaults to:
Height of image file "{name}" cannot exceed {size} px.
where:
{name}: will be replaced by the file name being uploaded.
{size}: will be replaced by the maxImageHeight setting.
string the upload progress bar CSS class to be applied when AJAX upload is in process (applicable only
for ajax uploads). Defaults to progress-bar progress-bar-success progress-bar-striped active.
stringthe upload progress bar CSS class to be applied when AJAX upload is complete. Defaults to progress-bar
progress-bar-success.
string the type of files that are to be displayed in the preview window. Defaults to image.
Can be one of the following:
image: Only image type files will be shown in preview.
text: Only text type files will be shown in preview.
any: Both image and text files content will be shown in preview.
Files other than image or text will be displayed as a thumbnail with the filename in
the preview window.
string the icon for zooming the file content in a new modal dialog. This is currently applicable only for text file previews. Defaults to <i class="glyphicon glyphicon-zoom-in"></i>
string the identifier for the container element displaying the error (e.g. '#id'). If not
set, will default to the container with CSS class kv-fileinput-error inside the preview container
(identified by elPreviewContainer). The msgErrorClass will be automatically appended
to this container before displaying the error.
string the identifier for the container element containing the caption (e.g. '#id'). If not
set, will default to the container with CSS class file-caption inside the main plugin container.
string the identifier for the container element containing the caption text (e.g. '#id').
If not set, will default to the container with CSS class file-caption-name inside the main plugin
container.
string the identifier for the container element containing the preview (e.g. '#id'). If not
set, will default to the container with CSS class file-preview inside the main plugin container.
string the identifier for the element containing the preview image thumbnails (e.g. '#id').
If not set, will default to the container with CSS class file-preview-thumbnails inside the main
plugin container.
string the identifier for the element containing the preview progress status (e.g. '#id').
If not set, will default to the container with CSS class file-preview-status inside the main plugin
container.
function a callback to convert the filename as a slug string eliminating special characters. If not set,
it will use the plugin's own internal slugDefault method. This callback function includes the
filename as parameter and must return a converted filename string.
Example:
slugCallback: function(filename) {
return filename.replace('(', '_');
}
bool whether to enable a drag and drop zone for dragging and dropping files to. This is available only
for ajax based uploads. Defaults to true.
string title to be displayed in the drag and drop zone. This is available only for ajax based uploads.
Defaults to Drag & drop files here ….
string CSS class for the drag & drop zone title. Defaults to file-drop-zone-title.
object configuration for setting up file actions for newly selected file thumbnails in the preview window. The following properties can be set: The following properties can be set:
removeIcon: string, icon for remove button to be displayed in each file thumbnail.
removeClass: string, CSS class for the remove button in each file thumbnail.
removeTitle: string, title for remove button in each file thumbnail.
uploadIcon: string, icon for upload button to be displayed in each file thumbnail.
uploadClass: string, CSS class for the remove button in each file thumbnail.
uploadTitle: string, title for remove button in each file thumbnail.
indicatorNew: string, an indicator (HTML markup) for new pending upload displayed in
each file thumbnail.
indicatorSuccess: string, an indicator (HTML markup) for successful upload displayed
in each file thumbnail.
indicatorError: string, an indicator (HTML markup) for error in upload displayed in
each file thumbnail.
indicatorLoading: string, an indicator (HTML markup) for ongoing upload displayed in
each file thumbnail.
indicatorNewTitle: string, title to display on hover of indicator for new pending
upload in each file thumbnail.
indicatorSuccessTitle: string, title to display on hover of indicator for successful
in each file thumbnail.
indicatorErrorTitle: string, title to display on hover of indicator for error in
upload in each file thumbnail.
indicatorLoadingTitle: string, title to display on hover of indicator for ongoing
upload in each file thumbnail.
Defaults to the following setting:
{
removeIcon: '<i class="glyphicon glyphicon-trash text-danger"></i>',
removeClass: 'btn btn-xs btn-default',
removeTitle: 'Remove file',
uploadIcon: '<i class="glyphicon glyphicon-upload text-info"></i>',
uploadClass: 'btn btn-xs btn-default',
uploadTitle: 'Upload file',
indicatorNew: '<i class="glyphicon glyphicon-hand-down text-warning"></i>',
indicatorSuccess: '<i class="glyphicon glyphicon-ok-sign file-icon-large text-success"></i>',
indicatorError: '<i class="glyphicon glyphicon-exclamation-sign text-danger"></i>',
indicatorLoading: '<i class="glyphicon glyphicon-hand-up text-muted"></i>',
indicatorNewTitle: 'Not uploaded yet',
indicatorSuccessTitle: 'Uploaded',
indicatorErrorTitle: 'Upload Error',
indicatorLoadingTitle: 'Uploading ...'
}
string markup for additional action buttons to display within the initial preview thumbnails (for example displaying an image edit button). The following tags can be used in the markup and will be automatically replaced:
{dataKey}: Will be replaced with the key set within
initialPreviewConfig.
string the encoding to be used while reading a text file. Applicable only for previewing text files.
Defaults to UTF-8.
object additional ajax settings to pass to the plugin before submitting the ajax request for upload. Applicable only for ajax uploads. This can be useful to pass additional tokens to headers or one can use it for setting other ajax options for advanced cases. Refer the jQuery ajax documentation for the various settings you can configure.
object additional ajax settings to pass to the plugin before submitting the delete ajax request in each initial preview thumbnail. Applicable only for ajax deletions. This can be useful to pass additional tokens to headers or one can use it for setting other ajax options for advanced cases. Refer the jQuery ajax documentation for the various settings you can configure.
boolean whether to show details of the error stack from the server log when an error is encountered via
ajax response. Defaults to true.
The plugin supports various events and allows advanced features like returning event results for validating and manipulating your file upload dynamically. The section is categorized into file events, error events, and event manipulation.
This event is triggered when the file input the remove button is pressed for clearing the file preview.
Example:
$('#input-id').on('fileclear', function(event) {
console.log("fileclear");
});
This event is triggered after the files in the preview are cleared.
Example:
$('#input-id').on('filecleared', function(event) {
console.log("filecleared");
});
This event is triggered after a file is loaded in the preview. Additional parameters available are:
file: the file object instance
previewId: the identifier for the preview file container
index: the zero-based sequential index of the loaded file in the preview list
reader: the FileReader instance if available.
Example:
$('#input-id').on('fileloaded', function(event, file, previewId, index, reader) {
console.log("fileloaded");
});
This event is triggered when the file input is reset to initial value.
Example:
$('#input-id').on('filereset', function(event) {
console.log("filereset");
});
This event is triggered when each file image is fully loaded in the preview window. This is only applicable for image
file previews and if showPreview is set to true. Additional parameters available are:
previewId: the identifier for the preview file container.
Example:
$('#input-id').on('fileimageloaded', function(event, previewId) {
console.log("fileimageloaded");
});
This event is triggered when the file browse button is clicked to open the file selection dialog.
Example:
$('#input-id').on('filebrowse', function(event) {
console.log("File browse triggered.");
});
This event is triggered after a batch of files are selected and displayed in the preview. Additional parameters available are:
files: the file stack array (or empty object if not available).
Example:
$('#input-id').on('filebatchselected', function(event, files) {
console.log('File batch selected triggered');
});
This event is triggered when no files are selected by the user for a repeat selection scenario (i.e. on a file input that already contains previously selected files). This event is better applicable for browsers like Google Chrome, which clear the file input when the file selection dialog is cancelled. For other browsers, this event is typically triggered only when one resets the form or clears file input (using the remove button).
Example:
$('#input-id').on('fileselectnone', function(event) {
console.log("Huh! No files were selected.");
});
This event is triggered when the upload process is launched by clicking a upload button, and the entire widget is
locked (disabled) until upload is getting processed. Only the Cancel button will be enabled when the
file input is locked. Additional parameters available are:
filestack: the array of selected file objects.uploadExtraData: the uploadExtraData settings for the plugin (will return an empty
object if not set).
$('#input-id').on('filelock', function(event, filestack, extraData) {
var fstack = filestack.filter(function(n){ return n != undefined });
console.log('Files selected - ' + fstack.length);
});
This event is triggered when the upload process is completed (successfully or with error). The entire widget is unlocked (enabled) and reverts to initial state. Additional parameters available are:
filestack: the array of selected file objects.
uploadExtraData: the uploadExtraData settings for the plugin (will return an empty
object if not set).
$('#input-id').on('fileunlock', function(event, filestack, extraData) {
var fstack = filestack.filter(function(n){ return n != undefined });
console.log('Files selected - ' + fstack.length);
});
This event is triggered before deletion of each thumbnail file in the initialPreview content set.
Additional parameters available are:
key: the key passed within initialPreviewConfig for the selected file for delete.
jqXHR: the jQuery XMLHttpRequest object used for this transaction (if available).
data: the output of deleteExtraData object.
$('#input-id').on('filepredelete', function(event, key) {
console.log('Key = ' + key);
});
This event is triggered after deletion of each thumbnail file in the initialPreview content set.
Additional parameters available are:
key: the key passed within initialPreviewConfig for the selected file that will be
passed as POST data to the url.
jqXHR: the jQuery XMLHttpRequest object used for this transaction (if available).
data: the output of deleteExtraData object.
$('#input-id').on('filedeleted', function(event, key) {
console.log('Key = ' + key);
});
This event is triggered before submission of the upload ajax request. You could use this event to manipulate the uploadExtraData before its submitted via ajax. The following additional parameters are also available specifically and only if the upload is triggered via each thumbnail upload button.
previewId: the identifier of each file's parent thumbnail div element in the preview window.
index: the zero-based index of the file in the file stack.
$('#input-id').on('filepreajax', function(event, previewId, index) {
console.log('File pre ajax triggered');
});
This event is triggered only for ajax uploads and before upload of each thumbnail file. This event is triggered after filepreajax and within the ajax beforeSend event. Additional parameters available are:
data: This is a data object (associative array) that sends the following information, whose
keys are:
form: the FormData object which is passed via XHR2 (or empty object if not available).
files: the file stack array (or empty object if not available).
extra: the uploadExtraData settings for the plugin (or empty object if not
available).
response: the data sent via ajax response (or empty object if not available).
reader: the FileReader instance if available.
jqXHR: the jQuery XMLHttpRequest object used for this transaction (if
available).
previewId: the identifier of each file's parent thumbnail div element in the preview window.
index: the zero-based index of the file in the file stack.
$('#input-id').on('filepreupload', function(event, data, previewId, index) {
var form = data.form, files = data.files, extra = data.extra,
response = data.response, reader = data.reader;
console.log('File pre upload triggered');
});
This event is triggered only for ajax uploads and after upload is completed for each thumbnail file. This event is triggered ONLY for ajax uploads and in the following scenarios:
When the upload icon in each preview thumbnail is clicked and file is uploaded successfully, OR
When you have uploadAsync set to true and you have triggered batch upload. In this
case, the fileuploaded event is triggered after every individual selected file is uploaded
successfully.
The additional parameters available with this eventare:
data: This is a data object (associative array) that sends the following information, whose
keys are:
form: the FormData object which is passed via XHR2 (or empty object if not available).
files: the file stack array (or empty object if not available).
extra: the uploadExtraData settings for the plugin (or empty object if not
available).
response: the data sent via ajax response (or empty object if not available).
reader: the FileReader instance if available.
jqXHR: the jQuery XMLHttpRequest object used for this transaction (if
available).
previewId: the identifier of each file's parent thumbnail div element in the preview window.
index: the zero-based index of the file in the file stack.
$('#input-id').on('fileuploaded', function(event, data, previewId, index) {
var form = data.form, files = data.files, extra = data.extra,
response = data.response, reader = data.reader;
console.log('File uploaded triggered');
});
This event is triggered only for ajax uploads and before a batch upload (for both synchronous and asynchronous uploads) after the upload button is clicked. Additional parameters available are:
data: This is a data object (associative array) that sends the following information, whose
keys are:
form: the FormData object which is passed via XHR2 (or empty object if not available).
files: the file stack array (or empty object if not available).
extra: the uploadExtraData settings for the plugin (or empty object if not
available).
response: the data sent via ajax response (or empty object if not available).
reader: the FileReader instance if available.
jqXHR: the jQuery XMLHttpRequest object used for this transaction (if
available).
$('#input-id').on('filebatchpreupload', function(event, data, previewId, index) {
var form = data.form, files = data.files, extra = data.extra,
response = data.response, reader = data.reader;
console.log('File batch pre upload');
});
This event is triggered only for ajax uploads and after a successful synchronous batch upload. This event is triggered ONLY for ajax uploads and in the following scenario:
When you have uploadAsync set to false and you have triggered batch upload. In this
case, the filebatchuploadsuccess event is triggered after all files have been successfully uploaded.
The additional parameters available with this event are:
data: This is a data object (associative array) that sends the following information, whose
keys are:
form: the FormData object which is passed via XHR2 (or empty object if not available).
files: the file stack array (or empty object if not available).
extra: the uploadExtraData settings for the plugin (or empty object if not
available).
response: the data sent via ajax response (or empty object if not available).
reader: the FileReader instance if available.
jqXHR: the jQuery XMLHttpRequest object used for this transaction (if
available).
$('#input-id').on('filebatchuploadsuccess', function(event, data, previewId, index) {
var form = data.form, files = data.files, extra = data.extra,
response = data.response, reader = data.reader;
console.log('File batch upload success');
});
This event is triggered only for ajax uploads and after completion of either the synchronous OR asynchronous ajax batch upload. Additional parameters available are:
files: the file stack array (or empty object if not available).
extra: the uploadExtraData settings for the plugin (or empty object if not
available).
$('#input-id').on('filebatchuploadcomplete', function(event, files, extra) {
console.log('File batch upload complete');
});
This event is triggered after a successfully uploaded thumbnail is removed using the thumbnail delete button. This is
usually applicable when you have showUploadedThumbs set to
true.
Additional parameters available are:
id: the HTML ID attribute for the thumbnail container element.
$('#input-id').on('filesuccessremove', function(event, id) {
if (some_processing_function(id)) {
console.log('Uploaded thumbnail successfully removed');
} else {
return false; // abort the thumbnail removal
}
});
This event is triggered when the file input widget is disabled (prevents any modification) using the
disable method.
$('#input-id').on('filedisabled', function(event) {
console.log('File disabled');
});
This event is triggered when the file input widget is enabled (allows modification) using the enable
method.
$('#input-id').on('fileenabled', function(event) {
console.log('File enabled');
});
This event is triggered when a client validation error is encountered for an uploaded file. This allows access to an object `data` as a parameter.
data: object/associative array containing the following
id: the preview thumbnail identifier (or undefined if not available)
index: the file index/preview thumbnail index (or undefined if not available)
file: the file object (or undefined if not available)
reader: the file reader instance (or undefined if not available)
files: the file stack array (or empty object if not available).
Example:
$('#input-id').on('fileerror', function(event, data) {
console.log(data.id);
console.log(data.index);
console.log(data.file);
console.log(data.reader);
console.log(data.files);
});
This event is triggered only for ajax uploads and when an upload or file input validation error is encountered primarily for ajax uploads. This event is triggered ONLY for ajax uploads and in the following scenarios:
When the upload icon in each preview thumbnail is clicked and file faced a validation error in upload, OR
When you have uploadAsync set to true and you have triggered batch upload. In
this case, the fileuploaderror event is triggered after any selected file faces an upload
validation error.
The additional parameters available with this event are:
data: This is a data object (associative array) that sends the following information, whose
keys are:
id: the preview thumbnail identifier (or undefined if not available)
index: the file index/preview thumbnail index (or undefined if not available)
form: the FormData object which is passed via XHR2 (or empty object if not
available).
files: the file stack array (or empty object if not available).
extra: the uploadExtraData settings for the plugin (or empty object if
not available).
response: the data sent via ajax response (or empty object if not available).
reader: the FileReader instance if available.
jqXHR: the jQuery XMLHttpRequest object used for this transaction (if
available).
$('#input-id').on('fileuploaderror', function(event, data, previewId, index) {
var form = data.form, files = data.files, extra = data.extra,
response = data.response, reader = data.reader;
console.log('File upload error');
});
This event is triggered only for ajax uploads and after an upload validation error is faced for synchronous batch upload. This event is triggered ONLY for ajax uploads and in the following scenario:
When you have uploadAsync set to false and you have triggered batch upload. In
this case, the filebatchuploaderror event is triggered after any file faces an upload error OR
you return an error via your server action JSON response.
The additional parameters available with this event are:
data: This is a data object (associative array) that sends the following information, whose
keys are:
form: the FormData object which is passed via XHR2 (or empty object if not
available).
files: the file stack array (or empty object if not available).
extra: the uploadExtraData settings for the plugin (or empty object if
not available).
response: the data sent via ajax response (or empty object if not available).
reader: the FileReader instance if available.
jqXHR: the jQuery XMLHttpRequest object used for this transaction (if
available).
$('#input-id').on('filebatchuploaderror', function(event, data) {
var form = data.form, files = data.files, extra = data.extra,
response = data.response, reader = data.reader;
console.log('File batch upload error');
});
This event is triggered when an error is faced in deletion of each thumbnail file in the
initialPreview content set. Additional parameters available are:
data: This is a data object (associative array) that sends the following information, whose
keys are:
id: the preview thumbnail identifier (or undefined if not available)
index: the file index/preview thumbnail index (or undefined if not available)
extra: the deleteExtraData settings for the plugin (or empty object if not
available).
response: the data sent via ajax response (or empty object if not available).
jqXHR: the jQuery XMLHttpRequest object used for this transaction (if
available).
$('#input-id').on('filedeleteerror', function(event, data) {
console.log('File delete error');
});
This event is triggered when a folder or multiple folders have been dragged & dropped to the file preview drop zone. Additional parameters available are:
folders: The count of folders dropped.
$('#input-id').on('filefoldererror', function(event, folders) {
console.log('File folder dropped error');
});
This event is triggered manually by the user from one of the other events by returning an error object from the source event. Refer Event Manipulation section for details. Additional parameters available are:
data This is a data object (associative array) that sends the following information, whose
keys are:
form: the FormData object which is passed via XHR2 (or empty object if not
available).
response: the aborted data sent when returned when triggering the validation error
from the source event.
files: the file stack array (or empty object if not available).
extra: the uploadExtraData settings for the plugin (or empty object if
not available).
reader: the FileReader instance if available.
jqXHR: the jQuery XMLHttpRequest object used for this transaction (if
available).
$("#input").on('filecustomerror', function(event, params) {
console.log(params.id);
console.log(params.index);
console.log(params.data);
});
With release v4.1.8, you can return data for most of the events and use it for advanced processing. This functionality is supported for most events listed above, but is not applicable for the following events.
fileclear
filecleared
filereset
fileerror
fileuploaderror
filebatchuploaderror
filedeleteerror
filefoldererror
filecustomerror
fileuploaded
filebatchuploadcomplete
filebatchuploadsuccess
For all the events other than ones mentioned above, you can set a custom validation error which will be triggered just before upload is initiated.
This will enable you to add your additional custom validations to enhance the fileinput to be used for innumerous
scenarios. It will allow an ability to return an associative object with any of the fileinput events (except the
except the events above) e.g. change, fileselect, filepreupload, filebatchpreupload
etc.
The object can return the following keys:
message: string, the validation error message to be displayed before upload. If this
is set the plugin will automatically abort the upload whenever called and display this as an error message.
You can use this property for example to read a file and perform your own custom validation.
data: object, an optional associative array of additional data at abort, that you can
pass for usage later.
STEP 1: You can trigger for example an error to abort from filepreupload
$('#input').on('filepreupload', function(event, data, previewId, index, jqXHR) {
// do your validation and return an error like below
if (customValidationFailed) {
return {
message: 'You are not allowed to do that',
data: {key1: 'Key 1', detail1: 'Detail 1'}
};
}
});
The above abort will be triggered at time of upload for (ajax uploads) OR at form submission (for non-ajax uploads).
STEP 2: Reading additional data at abort by trapping the filecustomerror event
$('#input').on('filecustomerror', function(event, params) {
// params.abortData will contain the additional abort data passed
// params.abortMessage will contain the aborted error message passed
});
As mentioned before, the above functionality of raising a filecustomerror is not supported in the
following events:
fileclear
filecleared
filereset
fileerror
fileuploaderror
filebatchuploaderror
filedeleteerror
filecustomerror
fileuploaded
filebatchuploadcomplete
filebatchuploadsuccess
The plugin supports the following methods. To view a demonstration of various plugin methods, click here.
Disable the file input.
$('#input-id').fileinput('disable');
Enable the file input.
$('#input-id').fileinput('enable');
Reset the file input.
$('#input-id').fileinput('reset');
Destroys the file input plugin and reverts to a normal native file input.
$('#input-id').fileinput('destroy');
Refreshes the file input plugin based on options provided. You can supply an array of plugin options as a parameter.
// example 1 (disable at runtime)
$('#input-id').attr('disabled', 'disabled');
$('#input-id').fileinput('refresh');
// example 2 (modify plugin options at runtime)
$('#input-id').fileinput('refresh', {browseLabel: 'Select...', removeLabel: 'Delete'});
Clear the file input.
$('#input-id').fileinput('clear');
Trigger ajax upload of the files that are selected. Applicable only if uploadUrl is set.
$('#input-id').fileinput('upload');
Cancel an ongoing ajax upload of the files.
$('#input-id').fileinput('cancel');
Locks the file input by disabling all actions/buttons except a cancel button to abort ongoing AJAX requests (for ajax uploads only).
$('#input-id').fileinput('lock');
Unlocks and enables the file input back again by reversing the outcome of the lock action.
$('#input-id').fileinput('unlock');
The plugin has been implemented as extensions in the following frameworks
| Sl. | Framework | Extension Source | Developed By | Extension Demo |
|---|---|---|---|---|
| 1. | Yii Framework 2.0 | Yii2 Widgets | Krajee | Yii2 File Input |
Do you know any other framework extension using this plugin which is not listed here? Tell us so that we can consider its inclusion in this list.
bootstrap-fileinput is released under the BSD 3-Clause License. See the bundled LICENSE.md
for details.
Top Comments & Discussion