uploader-browser
v0.0.1
Published
A lightweight and configurable loader plugin, it supports multiple file upload, file filtering, block upload, queue, progress tracking and other support
Maintainers
Readme
uploader-browser
A lightweight and configurable loader plugin, it supports multiple file upload, file filtering, block upload, queue, progress tracking and other support
多文件分片断点续传
Constructor
Uploader(arg)
适用于单文件分片断点续传
Arguments
url:string:上传接口地址file:File:上传的文件config:上传配置retryCount:number:上传失败后的重试次数;默认3(即上传失败后最多重试两次)concurrentLimit:number:分片上传的并发请求量,默认为3chunkSize:number:分片的大小,默认2 * 1024 * 1024,等于2MBforceDirect:boolean:上传强制采用直传方式,默认 `false
putExtra:自定义参数配置fname:string:可以覆盖file[name]params:object:放置自定义参数
Properties
uuid:string:实例的唯一IDfile:File:当前文件status:STATUS:实例状态
Methods
start():开始上传stop():停止上传,再次执行start()会继续上传reset():重置断点续传的记录,从分片0重新上传
Events
next:文件上传时触发。使用此事件来更新当前文件的上传进度。返回值:Progresscomplete:成功上传文件时触发。返回值:接口的响应数据error:发生错误时触发。返回值:包含错误消息,有时还包含文件和其他详细信息
uploaderMultiple(url,config)
适用于多文件分片断点续传
Arguments
url:string:上传接口地址config:上传配置retryCount:number:上传失败后的重试次数;默认3(即上传失败后最多重试两次)concurrentLimit:number:分片上传的并发请求量,默认为3chunkSize:number:分片的大小,默认2 * 1024 * 1024,等于2MBforceDirect:boolean:上传强制采用直传方式,默认 `false
Properties
files:Array<FileInfo>:队列
Methods
addFile(file,putExtra):将文件添加到队列中getFile(id):通过id返回指定的文件对象。返回值fileInforemoveFile(id):通过id删除指定的文件。返回值booleanstart():开始队列中的文件stop():停止队列,再次执行start()会继续按队列处理pause(id):通过id暂停或继续指定的文件。返回值boolean
Events
UploadProgress:文件上传时触发。使用此事件来更新当前文件的上传进度。返回值:Progress和FileInfoUploadComplete:队列中的所有文件处理完时触发。返回值:Array<FileInfo>FileUploaded:成功上传文件时触发。返回值:接口的响应数据和FileInfoFileUploadError:发生错误时触发。返回值:包含错误消息,有时还包含文件和其他详细信息
interface
Progress
total:object:整个文件的上传进度loaded:number:已上传的字节total:number:总共的字节percent:number:百分比,loaded / total* 100
chunks:Array<total>:分片的上传进度,以数组方式返回total:object
PutExtra:自定义参数配置
fname:string:可以覆盖file[name]params:object:放置自定义参数
FileInfo:文件信息
id:string:唯一IDname:string::文件名type:string::文件类型loaded:number::已传字节total:number::总字节percent:number::百分比status:number::状态
