基于html5的文件上传插件
Version: 0.0.1
Author: zhangxu [email protected]
- FileUploader
- ~FileUploader
- ~_defaults :
Object
- ~_acceptTypeList :
enum
- ~_errorList :
enum
- ~init(setting)
- ~_createUpLoader()
- ~reset()
- ~destory()
- ~upload()
- ~error(code, info)
- ~_log(text, [level])
- ~_valiate(file, callback)
- ~_checkImage(result) ⇒
Boolean
- ~_bindEvents()
- ~_fileHander(file)
- ~_executeEvents(eventName, file, opts)
- "beforeFileQueued" (file)
- "error" (file, data)
- "fileQueued" (file)
- "uploadStart" (file)
- "uploadAbort" (file)
- "uploadProgress" (file)
- "uploadComplete" (file)
- "uploadSuccess" (file, res)
- "uploadError" (file)
文件上传工具构建类
Kind: inner class of FileUploader
Param | Type | Description |
---|---|---|
settings | Object |
初始化参数集 |
默认参数配置
Kind: inner property of FileUploader
文件类型映射
Kind: inner enum of FileUploader
错误码映射
Kind: inner enum of FileUploader
上传工具实例化入口
Kind: inner method of FileUploader
Param | Type | Description |
---|---|---|
setting | Object |
初始化参数 |
setting.Debug | String |
是否开启调试模式,调试模式会在控制台打印日志 |
setting.id | String |
实例id |
setting.uploadUrl | String |
上传路径 |
setting.picker | String | jQuery | Document |
指定选择文件的按钮容器,可以是选择器,也可以是dom元素或jquery元素 |
setting.auto | Boolean |
读取文件后是否自动开始上传,默认自动上传 |
setting.responseType | String |
[json |
setting.acceptType | String |
[excel |
setting.data | Object |
上传过程中携带的参数 |
setting.sizeLimit | Number |
上传文件大小限制,默认不限制 单位是k |
setting.widthLimit | Number |
上传文件的宽度限制,仅在上传文件类型为图片的情况下生效,单位px |
setting.heightLimit | Number |
上传文件的高度限制,仅在上传文件类型为图片的情况下生效,单位px |
setting.events | Object |
上传过程中的事件 |
setting.events.beforeFileQueued | function |
在文件被加入读入内存前触发 |
setting.events.error | function |
校验出错触发 |
setting.events.fileQueued | function |
在文件准备上传时触发 |
setting.events.uploadStart | function |
在开始上传时触发 |
setting.events.uploadAbort | function |
上传中断时出触发 |
setting.events.uploadProgress | function |
上传过程中触发 |
setting.events.uploadComplete | function |
上传完成时出触发 |
setting.events.uploadSuccess | function |
上传成功时触发 |
setting.events.uploadError | function |
出错时触发,上传过程中出错 |
创建uploader实例
Kind: inner method of FileUploader
重置上传实例
Kind: inner method of FileUploader
销毁上传实例
Kind: inner method of FileUploader
开始上传,仅在auto为false时生效
Kind: inner method of FileUploader
报错函数
Kind: inner method of FileUploader
Param | Type | Description |
---|---|---|
code | Number |
错误码 详见错误码列表 |
info | String |
错误信息 |
本地日志打印,调试模式开启时在控制台打印日志
Kind: inner method of FileUploader
Param | Type | Default | Description |
---|---|---|---|
text | String |
需要打印的日志内容 | |
[level] | Number |
0 |
level 日志级别,选填,默认为0, |
Kind: inner method of FileUploader
Decription: 验证文件是否符合要求
Param | Type | Description |
---|---|---|
file | Object |
|
callback | function |
回调函数 |
核对图片尺寸
Kind: inner method of FileUploader
Param | Type |
---|---|
result | Object |
上传组件事件绑定
Kind: inner method of FileUploader
用fileReader对文件处理
Kind: inner method of FileUploader
Param | Type | Description |
---|---|---|
file | File |
从input上读入的文件 |
手动触发绑定过的事件,类似于trigger
Kind: inner method of FileUploader
Param | Type | Description |
---|---|---|
eventName | String |
事件名称 |
file | Object |
当前的文件 |
opts | Object | function |
其他数据或回调函数 |
在文件被加入读入内存前触发
Kind: event emitted by FileUploader
Param | Type | Description |
---|---|---|
file | file |
从本地读入的文件 |
校验出错触发
Kind: event emitted by FileUploader
Param | Type | Description |
---|---|---|
file | file |
从本地读入的文件 |
data | Object |
错误对象 |
data.code | number |
错误码,member:_errorList |
data.msg | string |
错误文案 |
在文件准备上传时触发
Kind: event emitted by FileUploader
Param | Type | Description |
---|---|---|
file | file |
从本地读入的文件 |
在开始上传时触发
Kind: event emitted by FileUploader
Param | Type | Description |
---|---|---|
file | file |
从本地读入的文件 |
上传中断时出触发
Kind: event emitted by FileUploader
Param | Type | Description |
---|---|---|
file | file |
从本地读入的文件 |
上传过程中触发
Kind: event emitted by FileUploader
Param | Type | Description |
---|---|---|
file | file |
从本地读入的文件 |
上传完成时出触发
Kind: event emitted by FileUploader
Param | Type | Description |
---|---|---|
file | file |
从本地读入的文件 |
上传成功时触发
Kind: event emitted by FileUploader
Param | Type | Description |
---|---|---|
file | file |
从本地读入的文件 |
res | Object | String |
服务器返回的内容 |
上传出错时触发,不包括校验时出错
Kind: event emitted by FileUploader
Param | Type | Description |
---|---|---|
file | file |
从本地读入的文件 |