Gathering detailed insights and metrics for bootstrap-fileinput-npm
Gathering detailed insights and metrics for bootstrap-fileinput-npm
npm install bootstrap-fileinput-npm
Typescript
Module System
Node Version
NPM Version
75.2
Supply Chain
99.1
Quality
74.8
Maintenance
50
Vulnerability
100
License
JavaScript (93.67%)
SCSS (3.27%)
CSS (2.94%)
Batchfile (0.11%)
Total Downloads
32,324
Last Day
1
Last Week
6
Last Month
23
Last Year
548
5,366 Stars
1,307 Commits
2,388 Forks
375 Watching
3 Branches
138 Contributors
Minified
Minified + Gzipped
Latest Version
4.2.8
Package Id
bootstrap-fileinput-npm@4.2.8
Size
102.57 kB
NPM Version
3.3.9
Node Version
4.2.1
Cumulative downloads
Total Downloads
Last day
-50%
1
Compared to previous day
Last week
0%
6
Compared to previous week
Last month
-54.9%
23
Compared to previous month
Last year
-43%
548
Compared to previous year
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.
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.
NOTE: The latest version of the plugin is v4.2.8 (dev-master). Refer the CHANGE LOG for details.
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.initialPreview
and initialCaption
properties in the plugin options
section for configuring this.filereset
, fileclear
, filecleared
, fileloaded
, and fileerror
.fileimageuploaded
event that fires after image is completely loaded on the preview container.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']
.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
andallowedFileExtensions
.
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
.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.
uploadUrl
property.showPreview
is set to false, or uploadUrl is not supported plugin will degrade to normal form based upload.NOTE: Drag and Drop zone functionality, selectively appending or deleting files, and upload indicator with progress are ONLY AVAILABLE if you use AJAX BASED uploads (by setting
uploadUrl
).
View the plugin documentation and plugin demos at Krajee JQuery plugins.
You can use the bower
package manager to install. Run:
bower install bootstrap-fileinput
You can use the composer
package manager to install. Either run:
$ php composer.phar require kartik-v/bootstrap-fileinput "@dev"
or add:
"kartik-v/bootstrap-fileinput": "@dev"
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.
Step 1: Load the following assets in your header.
1<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"> 2<link href="path/to/css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" /> 3<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 4<!-- canvas-to-blob.min.js is only needed if you wish to resize images before upload. 5 This must be loaded before fileinput.min.js --> 6<script src="path/to/js/plugins/canvas-to-blob.min.js" type="text/javascript"></script> 7<script src="path/to/js/fileinput.min.js"></script> 8<!-- bootstrap.js below is only needed if you wish to the feature of viewing details 9 of text file preview via modal dialog --> 10<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" type="text/javascript"></script> 11<!-- optionally if you need translation for your language then include 12 locale file as mentioned below --> 13<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.
NOTE: The canvas-to-blob.min.js
file is the source for the JavaScript-Canvas-to-Blob plugin by blueimp. It is required to be loaded before fileinput.js
if you wish to use the image resize feature of the bootstrap-fileinput plugin. For ease of access, the plugin source for JavaScript-Canvas-to-Blob is included in the js/plugins
folder of this project repository.
Step 2: Initialize the plugin on your page. For example,
1// initialize with defaults 2$("#input-id").fileinput(); 3 4// with plugin options 5$("#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.
Alternatively, you can directly call the plugin options by setting data attributes to your input field.
1<input id="input-id" type="file" class="file" data-preview-file-type="text" >
As shown in the installation section, translations are now enabled with release 4.1.8. You can load a locale file /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. Use the sample locale file to copy and create a translation configuration for your own language.
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 display the close icon in the preview. Defaults to true
. This will be only parsed when showPreview
is true or when you are using the {close}
tag in your preview templates.
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 CSS class to be set for the button labels (i.e. browse, remove, upload, and cancel). Defaults to hidden-xs
, whereby labels are hidden for small screen devices.
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, the delimiter to be used to allow passing multiple content delimited as a string to initialPreview
. Defaults to '*$$*'
.
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:
1// for image files 2initialPreview: [ 3 "<img src='/images/desert.jpg' class='file-preview-image' alt='Desert' title='Desert'>", 4 "<img src='/images/jellyfish.jpg' class='file-preview-image' alt='Jelly Fish' title='Jelly Fish'>", 5], 6 7// for text files 8initialPreview: "<div class='file-preview-text' title='NOTES.txt'>" + 9 "This is the sample text file content upto wrapTextLength of 250 characters" + 10 "<span class='wrap-indicator' onclick='$(\"#show-detailed-text\").modal(\"show\")' title='NOTES.txt'>[…]</span>" + 11 "</div>" 12 13// for other files 14initialPreview: "<div class='file-preview-text'>" + 15 "<h2><i class='glyphicon glyphicon-file'></i></h2>" + 16 "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:
1// setup initial preview with data keys 2initialPreview: [ 3 "<img src='/images/desert.jpg' class='file-preview-image' alt='Desert' title='Desert'>", 4 "<img src='/images/jellyfish.jpg' class='file-preview-image' alt='Jelly Fish' title='Jelly Fish'>", 5], 6// initial preview configuration 7initialPreviewConfig: [ 8 { 9 caption: 'desert.jpg', 10 width: '120px', 11 url: '/localhost/avatar/delete', 12 key: 100, 13 extra: {id: 100} 14 }, 15 { 16 caption: 'jellyfish.jpg', 17 width: '120px', 18 url: '/localhost/avatar/delete', 19 key: 101, 20 frameClass: 'my-custom-frame-css', 21 frameAttr: { 22 style: 'height:80px', 23 title: 'My Custom Title', 24 }, 25 extra: function() { 26 return {id: $("#id").val()}; 27 }, 28 } 29]
Note: 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 passed either via initialPreviewConfig['extra']
OR deleteExtraData
format 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:
1// change thumbnail footer template 2layoutTemplates.footer = '<div class="file-thumbnail-footer">\n' + 3' <div class="file-caption-name">{caption}</div>\n' + 4' {CUSTOM_TAG_NEW}\n' + 5' {CUSTOM_TAG_INIT}\n' + 6' {actions}\n' + 7'</div>'; 8 9// set preview template tags 10previewThumbTags = { 11 '{CUSTOM_TAG_NEW}': '<span class="custom-css">CUSTOM MARKUP</span>', 12 '{CUSTOM_TAG_INIT}': ' ' 13};
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:
1// change thumbnail footer template 2layoutTemplates.footer = '<div class="file-thumbnail-footer">\n' + 3' <div class="file-caption-name">{caption}</div>\n' + 4' {CUSTOM_TAG_NEW}\n' + 5' {CUSTOM_TAG_INIT}\n' + 6' {actions}\n' + 7'</div>'; 8 9// setup initial preview with data keys 10initialPreview: [ 11 "<img src='/images/desert.jpg' class='file-preview-image' alt='Desert' title='Desert'>", 12 "<img src='/images/jellyfish.jpg' class='file-preview-image' alt='Jelly Fish' title='Jelly Fish'>", 13], 14 15// set initial preview template tags 16initialPreviewThumbTags = { 17 '{CUSTOM_TAG_NEW}': ' ', 18 '{CUSTOM_TAG_INIT}': '<span class="custom-css">CUSTOM MARKUP</span>' 19};
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 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:
1 {id: 100, value: '100 Details'}
As a function callback, it can be setup for example as:
1function() { 2 var obj = {}; 3 $('.your-form-class').find('input').each(function() { 4 var id = $(this).attr('id'), val = $(this).val(); 5 obj[id] = val; 6 }); 7 return obj; 8}
object | function the URL for deleting the image/content in the initial preview via AJAX post response. This will be overridden by the initialPreviewConfig['url']
property.
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 and within each preview thumbnail for async/single uploads). The upload progress bar when displayed within each thumbnail will be wrapped inside a container having a CSS class of file-thumb-progress
. 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.{close}
: will be replaced with the close (cross) icon (by default on top right of the preview window). The layout template to control this markup is layoutTemplates.close
.{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 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.Similarly, the progress
layout template can understand the following special tags which will be replaced:
{class}
: the CSS class as set in the progressClass
or progressCompleteClass
properties.The layoutTemplates
if not set will default to:
1{ 2 main1: '{preview}\n' + 3 '<div class="kv-upload-progress hide"></div>\n' + 4 '<div class="input-group {class}">\n' + 5 ' {caption}\n' + 6 ' <div class="input-group-btn">\n' + 7 ' {remove}\n' + 8 ' {cancel}\n' + 9 ' {upload}\n' + 10 ' {browse}\n' + 11 ' </div>\n' + 12 '</div>', 13 main2: '{preview}\n<div class="kv-upload-progress hide"></div>\n{remove}\n{cancel}\n{upload}\n{browse}\n', 14 preview: '<div class="file-preview {class}">\n' + 15 ' {close}\n' + 16 ' <div class="{dropClass}">\n' + 17 ' <div class="file-preview-thumbnails">\n' + 18 ' </div>\n' + 19 ' <div class="clearfix"></div>' + 20 ' <div class="file-preview-status text-center text-success"></div>\n' + 21 ' <div class="kv-fileinput-error"></div>\n' + 22 ' </div>\n' + 23 '</div>', 24 close: '<div class="close fileinput-remove">×</div>', 25 icon: '<span class="glyphicon glyphicon-file kv-caption-icon"></span>', 26 caption: '<div tabindex="-1" class="form-control file-caption {class}">\n' + 27 ' <span class="file-caption-ellipsis">…</span>\n' + 28 ' <div class="file-caption-name"></div>\n' + 29 '</div>', 30 btnDefault: '<button type="{type}" tabindex="500" title="{title}" class="{css}"{status}>{icon}{label}</button>', 31 btnLink: '<a href="{href}" tabindex="500" title="{title}" class="{css}"{status}>{icon}{label}</a>', 32 btnBrowse: '<div tabindex="500" class="{css}"{status}>{icon}{label}</div>', 33 modal: '<div id="{id}" class="modal fade">\n' + 34 ' <div class="modal-dialog modal-lg">\n' + 35 ' <div class="modal-content">\n' + 36 ' <div class="modal-header">\n' + 37 ' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>\n' + 38 ' <h3 class="modal-title">{heading} <small>{title}</small></h3>\n' + 39 ' </div>\n' + 40 ' <div class="modal-body">\n' + 41 ' <textarea class="form-control" style="font-family:Monaco,Consolas,monospace; height: {height}px;" readonly>{body}</textarea>\n' + 42 ' </div>\n' + 43 ' </div>\n' + 44 ' </div>\n' + 45 '</div>', 46 zoom: '<button type="button" class="btn btn-default btn-sm btn-block" title="{zoomTitle}: {caption}" onclick="{dialog}">\n' + 47 ' {zoomInd}\n' + 48 '</button>\n', 49 progress: '<div class="progress">\n' + 50 ' <div class="{class}" role="progressbar" aria-valuenow="{percent}" aria-valuemin="0" aria-valuemax="100" style="width:{percent}%;">\n' + 51 ' {percent}%\n' + 52 ' </div>\n' + 53 '</div>', 54 footer: '<div class="file-thumbnail-footer">\n' + 55 ' <div class="file-caption-name" style="width:{width}">{caption}</div>\n' + 56 ' {progress} {actions}\n' + 57 '</div>', 58 actions: '<div class="file-actions">\n' + 59 ' <div class="file-footer-buttons">\n' + 60 ' {upload}{delete}{other}' + 61 ' </div>\n' + 62 ' <div class="file-upload-indicator" tabindex="-1" title="{indicatorTitle}">{indicator}</div>\n' + 63 ' <div class="clearfix"></div>\n' + 64 '</div>', 65 actionDelete: '<button type="button" class="kv-file-remove {removeClass}" title="{removeTitle}"{dataUrl}{dataKey}>{removeIcon}</button>\n', 66 actionUpload: '<button type="button" class="kv-file-upload {uploadClass}" title="{uploadTitle}">{uploadIcon}</button>\n' 67};
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.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 buttonsbtnLink
: 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.The previewTemplates
if not set will default to:
1{ 2 generic: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}">\n' + 3 ' {content}\n' + 4 ' {footer}\n' + 5 '</div>\n', 6 html: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}">\n' + 7 ' <object class="file-object" data="{data}" type="{type}" width="{width}" height="{height}">\n' + 8 ' ' + DEFAULT_PREVIEW + '\n' + 9 ' </object>\n' + 10 ' {footer}\n' + 11 '</div>', 12 image: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}">\n' + 13 ' <img src="{data}" class="file-preview-image" title="{caption}" alt="{caption}" ' + STYLE_SETTING + '>\n' + 14 ' {footer}\n' + 15 '</div>\n', 16 text: '<div class="file-preview-frame{frameClass}" id="{previewId}" data-fileindex="{fileindex}">\n' + 17 ' <pre class="file-preview-text" title="{caption}" ' + STYLE_SETTING + '>{data}</pre>\n' + 18 ' <button type="button" class="btn btn-default btn-sm btn-block" title="{zoomText}: {caption}" onclick="{dialog}">\n' + 19 ' {zoomInd}\n' + 20 ' </button>\n' + 21 ' {footer}\n' + 22 '</div>', 23 video: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}" title="{caption}" ' + STYLE_SETTING + '>\n' + 24 ' <video width="{width}" height="{height}" controls>\n' + 25 ' <source src="{data}" type="{type}">\n' + 26 ' ' + DEFAULT_PREVIEW + '\n' + 27 ' </video>\n' + 28 ' {footer}\n' + 29 '</div>\n', 30 audio: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}" title="{caption}" ' + STYLE_SETTING + '>\n' + 31 ' <audio controls>\n' + 32 ' <source src="{data}" type="{type}">\n' + 33 ' ' + DEFAULT_PREVIEW + '\n' + 34 ' </audio>\n' + 35 ' {footer}\n' + 36 '</div>\n', 37 flash: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}" title="{caption}" ' + STYLE_SETTING + '>\n' + 38 ' <object class="file-object" type="application/x-shockwave-flash" width="{width}" height="{height}" data="{data}">\n' + 39 OBJECT_PARAMS + ' ' + DEFAULT_PREVIEW + '\n' + 40 ' </object>\n' + 41 ' {footer}\n' + 42 '</div>\n', 43 object: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}" title="{caption}" ' + STYLE_SETTING + '>\n' + 44 ' <object class="file-object" data="{data}" type="{type}" width="{width}" height="{height}">\n' + 45 ' <param name="movie" value="{caption}" />\n' + 46 OBJECT_PARAMS + ' ' + DEFAULT_PREVIEW + '\n' + 47 ' </object>\n' + 48 ' {footer}\n' + 49 '</div>', 50 other: '<div class="file-preview-frame{frameClass}" id="{previewId}" data-fileindex="{fileindex}"' + 51 ' title="{caption}" ' + STYLE_SETTING + '>\n' + 52 ' <div class="file-preview-other-frame">\n'+ 53 ' ' + DEFAULT_PREVIEW + '\n' + 54 ' </div>\n' + 55 ' <div class="file-preview-other-footer">{footer}</div>\n' + 56 '</div>' 57}
The values of the constants used in the above templates are as follows:
1STYLE_SETTING = 'style="width:{width};height:{height};"', 2OBJECT_PARAMS = ' <param name="controller" value="true" />\n' + 3 ' <param name="allowFullScreen" value="true" />\n' + 4 ' <param name="allowScriptAccess" value="always" />\n' + 5 ' <param name="autoPlay" value="false" />\n' + 6 ' <param name="autoStart" value="false" />\n'+ 7 ' <param name="quality" value="high" />\n', 8DEFAULT_PREVIEW = '<div class="file-preview-other">\n' + 9 ' <span class="{previewFileIconClass}">{previewFileIcon}</span>\n' + 10 '</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.
1['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:
1['jpg', 'gif', 'png', 'txt']
NOTE: You need to be careful in case you are setting both
allowedFileTypes
andallowedFileExtensions
. In this case, theallowedFileTypes
property is validated first and generally precedes theallowedFileExtensions
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:
1['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.
string the default content / markup to show by default in the preview window whenever the files are cleared or the input is cleared. This can be useful for use cases like showing the default user profile picture or profile image before upload to overwrite. This is a bit different from initialPreview
in the sense, that the initialPreview
content will always be displayed unless it is deleted or overwritten based on overwriteInitial
. The defaultPreviewContent
on the other hand will only be shown ONLY on initialization OR whenever you clear the preview. At other times when files have been selected this will be overwritten temporarily until file(s) selected is/are cleared.
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.For example:
1// example 1 - tags with value set as string 2customLayoutTags: { 3 '{tagA}': '<span class="label label-default">Tag A</span>', 4 '{tagB}': 'Tag B', 5} 6 7// example 2 - tags with value set as callback 8customLayoutTags: { 9 '{tagC}': function() { 10 return $("#element-id").val(); 11 } 12}
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.For example:
1// example 1 - tags with value set as string 2customPreviewTags: { 3 '{tagA}': '<span class="label label-default">Tag A</span>', 4 '{tagB}': 'Tag B', 5} 6 7// example 2 - tags with value set as callback 8customPreviewTags: { 9 '{tagC}': function() { 10 return $("#element-id").val(); 11 } 12}
object the format settings (width and height) for rendering each preview file type. This is by default setup as following:
1{ 2 image: {width: "auto", height: "160px"}, 3 html: {width: "213px", height: "160px"}, 4 text: {width: "160px", height: "136px"}, 5 video: {width: "213px", height: "160px"}, 6 audio: {width: "213px", height: "80px"}, 7 flash: {width: "213px", height: "160px"}, 8 object: {width: "160px", height: "160px"}, 9 other: {width: "160px", height: "160px"} 10}
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:
1// vType: is the file mime type 2// vName: is the file name 3{ 4 image: function(vType, vName) { 5 return (typeof vType !== "undefined") ? vType.match('image.*') : vName.match(/\.(gif|png|jpe?g)$/i); 6 }, 7 html: function(vType, vName) { 8 return (typeof vType !== "undefined") ? vType == 'text/html' : vName.match(/\.(htm|html)$/i); 9 }, 10 text: function(vType, vName) { 11 return typeof vType !== "undefined" && vType.match('text.*') || vName.match(/\.(txt|md|csv|nfo|php|ini)$/i); 12 }, 13 video: function (vType, vName) { 14 return typeof vType !== "undefined" && vType.match(/\.video\/(ogg|mp4|webm)$/i) || vName.match(/\.(og?|mp4|webm)$/i); 15 }, 16 audio: function (vType, vName) { 17 return typeof vType !== "undefined" && vType.match(/\.audio\/(ogg|mp3|wav)$/i) || vName.match(/\.(ogg|mp3|wav)$/i); 18 }, 19 flash: function (vType, vName) { 20 return typeof vType !== "undefined" && vType == 'application/x-shockwave-flash' || vName.match(/\.(swf)$/i); 21 }, 22 object: function (vType, vName) { 23 return true; 24 }, 25 other: function (vType, vName) { 26 return true; 27 }, 28}
string the default 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:
1previewFileIconSettings: { 2 'doc': '<i class="fa fa-file-word-o text-primary"></i>', 3 'xls': '<i class="fa fa-file-excel-o text-success"></i>', 4 'ppt': '<i class="fa fa-file-powerpoint-o text-danger"></i>', 5 'jpg': '<i class="fa fa-file-photo-o text-warning"></i>', 6 'pdf': '<i class="fa fa-file-pdf-o text-danger"></i>', 7 'zip': '<i class="fa fa-file-archive-o text-muted"></i>', 8}
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 previewYou 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:
1previewFileExtSettings: { 2 'doc': function(ext) { 3 return ext.match(/(doc|docx)$/i); 4 }, 5 'xls': function(ext) { 6 return ext.match(/(xls|xlsx)$/i); 7 }, 8 'ppt': function(ext) { 9 return ext.match(/(ppt|pptx)$/i); 10 } 11}
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 cancel button. Defaults to Cancel
.
string the icon to display before the label for the file picker/remove button. Defaults to <i class="glyphicon glyphicon-ban-circle"></i>
.
string the CSS class for the file cancel button. Defaults to btn btn-default
.
string the title to display on hover for the file cancel button. Defaults to Abort ongoing upload
.
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.
bool whether the batch upload of multiple files will be asynchronous/in parallel. Defaults to true
.
object | function the extra data that will be passed as data to the url/AJAX server call via POST. 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:
1 {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)1// previewId and index is only available for individual file upload via the thumbnail 2function (previewId, index) { 3 var obj = {}; 4 $('.your-form-class').find('input').each(function() { 5 var id = $(this).attr('id'), val = $(this).val(); 6 obj[id] = val; 7 }); 8 return obj; 9}
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 maximum allowed image width in px
if you are uploading image files. Defaults to null
which means no limit on image width. Note that if you set resizeImage
property to true
, then the entire image will be resized within this 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. Note that if you set resizeImage
property to true
, then the entire image will be resized within this height.
bool whether to add ability to resize uploaded images. Defaults to false
. Note that resizing images requires HTML5 canvas support which is supported on most modern browsers. In addition, you must include the JavaScript-Canvas-to-Blob plugin by blueimp by including canvas-to-blob.js
in your application. This JS file must be loaded before fileinput.js
on the page. The JavaScript-Canvas-to-Blob source files are available in js/plugins
folder of bootstrap-fileinput project page. The canvas-to-blob.js
plugin is a polyfill for canvas.toBlob
method and is needed for allowing the resized image files via HTML5 canvas to be returned as a blob.
string preference to resize the image based on width
or height
. Defaults to width
. This property is parsed only when resizeImage
is true
. If set to width
, the maxImageWidth
property is first tested and if image size is greater than this, then the image is resized to maxImageWidth
. The image height
is resized and adjusted in the same ratio as width
. In case, the image width is already less than maxImageWidth
then the maxImageHeight
property is used to resize and width is adjusted in same ratio.
This will behave conversely, when resizePreference
is set to height
- the maxImageHeight
will be first tested against image height and then the rest of steps will be similarly parsed with preference given to height
instead of width
as before. For example:
1// Example for resizePreference = 'width' 2// - will resize image width to 200 px if image width is > 200 px 3// - will resize image height to 200 px if image width is < 200 px and 4// image height is > 200 px 5// if none of the above image will be returned as is 6$('#file-input').fileinput({ 7 resizeImage: true, 8 maxImageWidth: 200, 9 maxImageHeight: 200, 10 resizePreference: 'width' 11});
float the quality of the resized image. This must be a decimal number between 0.00
to 1.00
. Defaults to 0.92
.
string the default image mime type of the converted image after resize. Defaults to image/jpeg
.
float the maximum file size for upload in KB. If set to 0
, it means size allowed is unlimited. Defaults to 0
.
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. 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}" (<b>{size} KB</b>) exceeds maximum allowed upload size of <b>{maxSize} KB</b>. 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 the 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 <b>{n}</b> {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 <b>({n})</b> exceeds maximum allowed limit of <b>{m}</b>. 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 uploadedstring 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 uploadedstring 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 uploadedstring 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 uploadedstring 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 uploadedstring 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 message to be displayed when an ongoing ajax file upload is aborted by pressing the Cancel button. Defaults to The file upload was aborted
. If this is set to null or empty, the internal ajax error message will be displayed.
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 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:
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 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 error message to be displayed when a resize validation error occurs due to invalid image dimensions. Defaults to:
Could not get the image dimensions to resize.
string the exception message to be displayed when any javascript exception is thrown during resizing of the image. Defaults to:
Error while resizing the image.<pre>{errors}</pre>.
where:
{errors}
: will be replaced with the exception error message.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
.
string the 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.No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
5 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 6
Reason
Found 7/30 approved changesets -- score normalized to 2
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More