Bootstrap FileInput中文API整理

Bootstrap FileInput中文API整理

这段时间做项目用到bootstrap fileinput插件上传文件,在用的过程中,网上能查到的api都不是很全,所以想着整理一份比较详细的文档,方便自己今后使用,也希望能给大家带来帮助,如有错误,希望大家积极指正。

一、    引入文件

二、    初始化设置:

$("#uploadfile").fileinput({

                language: 'zh', //设置语言

                uploadUrl:"http://127.0.0.1/testDemo/fileupload/upload.do", //上传的地址

               allowedFileExtensions: ['jpg', 'gif', 'png'],//接收的文件后缀

               //uploadExtraData:{"id": 1, "fileName":'123.mp3'},

                uploadAsync: true, //默认异步上传

                showUpload:true, //是否显示上传按钮

                showRemove :true, //显示移除按钮

                showPreview :true, //是否显示预览

                showCaption:false,//是否显示标题

                browseClass:"btn btn-primary", //按钮样式    

               dropZoneEnabled: false,//是否显示拖拽区域

               //minImageWidth: 50, //图片的最小宽度

               //minImageHeight: 50,//图片的最小高度

               //maxImageWidth: 1000,//图片的最大宽度

               //maxImageHeight: 1000,//图片的最大高度

                //maxFileSize:0,//单位为kb,如果为0表示不限制文件大小

               //minFileCount: 0,

                maxFileCount:10, //表示允许同时上传的最大文件个数

                enctype:'multipart/form-data',

               validateInitialCount:true,

                previewFileIcon: "",

               msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}!",

           }).on("fileuploaded", function (event, data, previewId, index){


});

三、    Options 说明:

属性名属性类型描述说明默认值

languageString                       多语言设置,使用时需提前引入\locales文件夹下对应的语言文件,中文zh,引入语言文件必须放在fileinput.js之后'en'

showCaptionBoolean是否显示被选文件的简介true

showBrowseBoolean是否显示浏览按钮true

showPreviewBoolean是否显示预览区域true

showRemoveBoolean是否显示移除按钮true,

showUploadBoolean是否显示上传按钮true,

showCancelBoolean是否显示取消按钮true,

showClose:Boolean是否显示关闭按钮true

showUploadedThumbsBoolean true

browseOnZoneClickBoolean false

autoReplaceBoolean是否自动替换当前图片,设置为true时,再次选择文件, 会将当前的文件替换掉。false

generateFileIdObject null

previewClassString添加预览按钮的类属性‘’

captionClassString ‘’

frameClassString 'krajee-default'

mainClassString 'file-caption-main'

mainTemplateObject null

purifyHtmlBoolean true

fileSizeGetterObject null

initialCaptionString ''

initialPreviewArray/Object []

initialPreviewDelimiterString '*$$*'

initialPreviewAsDataBoolean false

initialPreviewFileTypeString 'image'

initialPreviewConfigArray/Object []

initialPreviewThumbTagsArray/Object []

previewThumbTagsObject {}

initialPreviewShowDeleteBoolean true

removeFromPreviewOnErrorBoolean false

deleteUrlString删除图片时的请求路径''

deleteExtraDataObject删除图片时额外传入的参数{}

overwriteInitialBoolean true

previewZoomButtonIconsObject {

prev: '',

  next: '',

  toggleheader: '',

  fullscreen: '',

  borderless: '',

  close: ''

},

previewZoomButtonClassesObject {

  prev: 'btn btn-navigate',

  next: 'btn btn-navigate',

  toggleheader: 'btn btn-default btn-header-toggle',

  fullscreen: 'btn btn-default',

  borderless: 'btn btn-default',

  close: 'btn btn-default'

},

preferIconicPreviewBoolrean false

preferIconicZoomPreviewBoolrean false

allowedPreviewTypesundefined undefined

allowedPreviewMimeTypesObject null

allowedFileTypesObject接收的文件后缀,如['jpg', 'gif', 'png'],不填将不限制上传文件后缀类型null

allowedFileExtensionsObject null

defaultPreviewContentObject null

customLayoutTagsObject {}

customPreviewTagsObject {}

previewFileIconString ''

previewFileIconClassString 'file-other-icon'

previewFileIconSettingsObject {}

previewFileExtSettingsObject {}

buttonLabelClassString 'hidden-xs'

browseIconString ' '

browseClassString 'btn btn-primary'

removeIconString ''

removeClassString 'btn btn-default'

cancelIconString ''

cancelClassString 'btn btn-default'

uploadIconString ''

uploadClassString 'btn btn-default'

uploadUrlString上传文件路径null

uploadAsyncboolean是否为异步上传true

uploadExtraData 上传文件时额外传递的参数设置{}

zoomModalHeightnumber 480

minImageWidthString图片的最小宽度null

minImageHeightString图片的最小高度null

maxImageWidthString图片的最大宽度null

maxImageHeightString图片的最大高度null

resizeImageboolean false

resizePreferenceString 'width'

resizeQualitynumber 0.92

resizeDefaultImageTypeString 'image/jpeg'

minFileSizenumber单位为kb,上传文件的最小大小值0

maxFileSizenumber单位为kb,如果为0表示不限制文件大小0

resizeDefaultImageTypenumber 25600(25MB)

minFileCountnumber表示同时最小上传的文件个数0

maxFileCountnumber表示允许同时上传的最大文件个数0

validateInitialCountboolean false

msgValidationErrorClassString 'text-danger'

msgValidationErrorIconString ' '

msgErrorClassString 'file-error-message'

progressThumbClassString "progress-bar progress-bar-success progress-bar-striped active"

rogressClassString "progress-bar progress-bar-success progress-bar-striped active"

progressCompleteClassString "progress-bar progress-bar-success"

progressErrorClassString "progress-bar progress-bar-danger"

progressUploadThresholdnumber 99

previewFileTypeString预览文件类型,内置['image', 'html', 'text', 'video', 'audio', 'flash', 'object',‘other‘]等格式'image'

elCaptionContainerString null

elCaptionTextString设置标题栏提示信息null

elPreviewContainerString null

elPreviewImageString null

elPreviewStatusString null

elErrorContainerString null

errorCloseButtonString '×'

slugCallbackString null

dropZoneEnabledboolean是否显示拖拽区域true

dropZoneTitleClassString拖拽区域类属性设置'file-drop-zone-title'

fileActionSettingsObject设置预览图片的显示样式{

    showRemove: true,

    showUpload: false,

    showZoom: true,

    showDrag: true,

    removeIcon: '',

    removeClass: 'btn btn-xs btn-default',

    removeTitle: 'Remove file',

    uploadIcon: '',

    uploadClass: 'btn btn-xs btn-default',

    uploadTitle: 'Upload file',

    zoomIcon: '',

    zoomClass: 'btn btn-xs btn-default',

    zoomTitle: 'View Details',

    dragIcon: '',

    dragClass: 'text-info',

    dragTitle: 'Move / Rearrange',

    dragSettings: {},

    indicatorNew: '',

    indicatorSuccess: '',

    indicatorError: '',

    indicatorLoading: '',

    indicatorNewTitle: 'Not uploaded yet',

    indicatorSuccessTitle: 'Uploaded',

    indicatorErrorTitle: 'Upload Error',

    indicatorLoadingTitle: 'Uploading ...'

}

otherActionButtonsString ''

textEncodingString编码设置'UTF-8'

ajaxSettingsObject {}

ajaxDeleteSettingsObject {}

showAjaxErrorDetailsboolean true

四、    提示说明设置:

属性名默认值中文

fileSinglefile文件

filePluralfiles个文件

browseLabelBrowse &hellip选择 …

removeLabelRemove移除

removeTitleClear selected files清除选中文件

cancelLabelCancel取消

cancelTitleAbort ongoing upload取消进行中的上传

uploadLabelUpload上传

uploadTitleUpload selected files上传选中文件

msgNoNo没有

msgNoFilesSelectedNo files selected“”

msgCancelledCancelled取消

msgZoomModalHeadingDetailed Preview详细预览

msgSizeTooSmallFile "{name}" ({size} KB) is too small and must be larger than {minSize} KB.File "{name}" ({size} KB) is too small and must be larger than {minSize} KB.

msgSizeTooLargeFile "{name}" ({size} KB) exceeds maximum allowed upload size of {maxSize} KB.文件 "{name}" ({size} KB) 超过了允许大小 {maxSize} KB.

msgFilesTooLessYou must select at least {n} {files} to upload.你必须选择最少 {n} {files} 来上传.

msgFilesTooManyNumber of files selected for upload ({n}) exceeds maximum allowed limit of {m}.选择的上传文件个数 ({n}) 超出最大文件的限制个数 {m}.

msgFileNotFoundFile "{name}" not found!文件 "{name}" 未找到!

msgFileSecuredSecurity restrictions prevent reading the file "{name}".安全限制,为了防止读取文件 "{name}".

msgFileNotReadableFile "{name}" is not readable.文件 "{name}" 不可读.

msgFilePreviewAbortedFile preview aborted for "{name}".取消 "{name}" 的预览.

msgFilePreviewErrorAn error occurred while reading the file "{name}".读取 "{name}" 时出现了一个错误.

msgInvalidFileNameInvalid or unsupported characters in file name "{name}".Invalid or unsupported characters in file name "{name}".

msgInvalidFileTypeInvalid type for file "{name}". Only "{types}" files are supported.不正确的类型 "{name}". 只支持 "{types}" 类型的文件.

msgInvalidFileExtensionInvalid extension for file "{name}". Only "{extensions}" files are supported.不正确的文件扩展名 "{name}". 只支持 "{extensions}" 的文件扩展名.

msgFileTypes{

            'image': 'image',

            'html': 'HTML',

            'text': 'text',

            'video': 'video',

            'audio': 'audio',

            'flash': 'flash',

            'pdf': 'PDF',

            'object': 'object'

        },

{

            'image': 'image',

            'html': 'HTML',

            'text': 'text',

            'video': 'video',

            'audio': 'audio',

            'flash': 'flash',

            'pdf': 'PDF',

            'object': 'object'

        },

msgUploadAbortedThe file upload was aborted该文件上传被中止

msgUploadThresholdProcessing...Processing...

msgUploadBeginInitializing...Initializing...

msgUploadEndDoneDone

msgUploadEmptyNo valid data available for upload.No valid data available for upload.

msgValidationErrorValidation Error验证错误

msgLoadingLoading file {index} of {files} …加载第 {index} 文件 共 {files} …

msgProgressLoading file {index} of {files} - {name} - {percent}% completed.加载第 {index} 文件 共 {files} - {name} - {percent}% 完成.

msgSelected{n} {files} selected{n} {files} 选中

msgFoldersNotAllowedDrag & drop files only! {n} folder(s) dropped were skipped.只支持拖拽文件! 跳过 {n} 拖拽的文件夹.

msgImageWidthSmallWidth of image file "{name}" must be at least {size} px.宽度的图像文件的"{name}"的必须是至少{size}像素.

msgImageHeightSmallHeight of image file "{name}" must be at least {size} px.图像文件的"{name}"的高度必须至少为{size}像素.

msgImageWidthLargeWidth of image file "{name}" cannot exceed {size} px.宽度的图像文件"{name}"不能超过{size}像素.

msgImageHeightLargeHeight of image file "{name}" cannot exceed {size} px.图像文件"{name}"的高度不能超过{size}像素.

msgImageResizeErrorCould not get the image dimensions to resize.无法获取的图像尺寸调整。

msgImageResizeExceptionError while resizing the image.

{errors}

错误而调整图像大小。

{errors}

msgAjaxErrorSomething went wrong with the {operation} operation. Please try again later!Something went wrong with the {operation} operation. Please try again later!

msgAjaxProgressError{operation} failed{operation} failed

ajaxOperations{

            deleteThumb: 'file delete',

            uploadThumb: 'file upload',

            uploadBatch: 'batch file upload',

            uploadExtra: 'form data upload'

        },

{

            deleteThumb: 'file delete',

            uploadThumb: 'file upload',

            uploadBatch: 'batch file upload',

            uploadExtra: 'form data upload'

        },

dropZoneTitleDrag & drop files here …拖拽文件到这里 …
支持多文件同时上传

dropZoneClickTitle
(or click to select {files})
(或点击{files}按钮选择文件)

previewZoomButtonTitles{

            prev: 'View previous file',

            next: 'View next file',

            toggleheader: 'Toggle header',

            fullscreen: 'Toggle full screen',

            borderless: 'Toggle borderless mode',

            close: 'Close detailed preview'

        }

{

            prev: '预览上一个文件',

            next: '预览下一个文件',

            toggleheader: '缩放',

            fullscreen: '全屏',

            borderless: '无边界模式',

            close: '关闭当前预览'

        }

fileActionSettings {     removeTitle: '删除文件',

            uploadTitle: '上传文件',

            zoomTitle: '查看详情',

            dragTitle: '移动 / 重置',

            indicatorNewTitle: '没有上传',

            indicatorSuccessTitle: '上传',

            indicatorErrorTitle: '上传错误',

            indicatorLoadingTitle: '上传 ...'

        },

五、    Method说明:

方法名参数描述

fileerror 异步上传错误结果处理

$('#uploadfile').on('fileerror', function(event, data, msg) {


});

fileuploaded 异步上传成功结果处理

$("#uploadfile").on("fileuploaded", function (event, data, previewId, index) {


})

filebatchuploaderror 同步上传错误结果处理

$('#uploadfile').on('filebatchuploaderror', function(event, data, msg) {


});

filebatchuploadsuccess 同步上传成功结果处理

$('#uploadfile').on('filepreupload', function(event, data, previewId, index) {


});

filebatchselected 选择文件后处理事件

$("#fileinput").on("filebatchselected", function(event, files) {

});

upload 文件上传方法

$("#fileinput").fileinput("upload");

fileuploaded 上传成功后处理方法

$("#fileinput").on("fileuploaded", function(event, data, previewId, index) {

});

filereset  

fileclear 点击浏览框右上角X 清空文件前响应事件

$("#fileinput").on("fileclear",function(event, data, msg){

});

filecleared 点击浏览框右上角X 清空文件后响应事件

$("#fileinput").on("filecleared",function(event, data, msg){

});

fileimageuploaded 在预览框中图片已经完全加载完毕后回调的事件

filepreremove 缩略图删除事件

fileremoved 缩略图删除后的回调事件

六、    常见错误:

 (1)   当点击上传后,报错,提示你必须选择最少X个文件上传。

错误原因:html中input标签元素属性:data-min-file-count="2" 设置为X个文件,限制上传文件数。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,636评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,890评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,680评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,766评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,665评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,045评论 1 276
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,515评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,182评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,334评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,274评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,319评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,002评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,599评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,675评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,917评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,309评论 2 345
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,885评论 2 341