3.3.3 • Published 6 years ago

uxcore-uploader-extend v3.3.3

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Uxcore Uploader

npm package


uxcore-uploader component for react

$ git clone https://github.com/uxcore/uxcore-uploader
$ cd uxcore-uploader
$ npm start

see http://uxco.re/components/uploader/ for details.

上传组件, 封装UploadCore核心组件, 作为UI层.

API

reset()

重置文件队列

Props

nametypedefaultSince Ver.description
className
localestringzh-cn1.1.10国际化,目前支持 zh-cn, en-uspl-pl
fileListarray[]1.2.3用于展示的文件列表
isOnlyImgbooleanfalse1.2.1是否以图片形式展示
isVisualbooleanfalse2.0.0是否可视化展示
hideUploadIconbooleanfalse3.2.2在可视化展示下,达到容量(queueCapcity)后是否隐藏上传入口
corestring/Corenull唯一标识或者UploadCore对象, 防止重复创建, 当传入UploadCore对象时,下列参数和事件设置均无效
namestring'file'上传文件字段名称
urlstring''响应上传服务器地址
paramsobject/arraynull上传文件额外参数
headersarraynull上传文件额外头
withCredentialsboolfalse上传文件是否自动附带cookie等信息
timeoutint0上传超时限制 0表示不限制
chunkEnableboolfalse是否允许分片上传
chunkSizesize0文件分片大小, 默认单位b,0不分片
chunkRetriesint0文件分片上传重试次数
chunkProcessThreadsint2分片上传并发数
processThreadsint2文件上传并发数
queueCapcityint0队列容量,0无限;
autoPendingbooltrue是否选择后自动等待上传
multiplebooltrue是否多选
acceptstring/arraynull允许文件类型, chrome 下的已知问题
sizeLimitsize0文件大小限制, 0表示不限制
preventDuplicateboolfalse是否防止文件重复
readOnlyboolfalse3.0.0是否以只读方式显示图片,有该属性时请fileList不能为空
showErrFilebooltrue3.2.0是否显示上传出错的文件项
actionOnQueueLimitstringerror1.5.10当队列超长时采取的策略:error, 抛错;cover, 覆盖

fileList 的最小格式 (格式稍显麻烦,是为了 onChange 的返回值可以传回给 fileList)

[
    {
        name: '', // 文件名称,列表形式必填
        ext: '', // 文件扩展名。例如 jpg。可选,不填时无法根据类型展示对应图标
        fileType: '', // 文件 mimetypes 类型。 例如 image/jpg。 可选,不填时无法根据类型展示对应图标
        response: {
            url: xxx,  // 文件链接,必填
            canRemove: true, // 是否可以删除,可选
            downloadUrl: 'xxxx', // 下载 URL,可选
        }
    }
]

Events

nameargumentsdescription
onChangefileList在上传成功或文件移除后触发,返回文件队列,包括自己传入的fileList
onCancelfile文件移除后触发,上传的文件和默认列表的文件格式会有所不同,文件格式参见下面的 fileList 格式
onfileuploaderrorFile, Error文件上传失败

onChange 的 fileList 的枚举格式有如下几种

[
    // 上传后的文件的格式, response 即服务器返回的值
    {
        type: 'upload',
        ext: file.ext,
        name: file.name,
        response: JSON.parse(file.response.rawResponse.rawResponse)
    },
    // 预览用文件的格式, `props.fileList` 相关, responce 即 `props.fileList` 里传入的格式。
    {
        type: 'list',
        response: file
    },
    // 被删除的文件的格式
    {
        type: 'delete',
        subType: 'list/upload', // 与上面两种类型对应,用于解析 response
        response: file // 与上面的 subType 相对应
    }
]

Other Events

nameargumentsdescription
onqueueuploadstart队列上传开始
onqueueuploadend队列上传结束
onqueuefileaddedFile队列添加了一个文件
onqueuefilefilteredFile, Error队列过滤了一个文件
onqueueerrorError队列错误
onstatchangeStat文件统计发生变化
onfileuploadstartFile文件上传开始
onfileuploadpreparingFileRequest文件上传准备时
onfileuploadpreparedFile, FileRequest文件上传准备好了
onchunkuploadpreparingChunkRequest分块上传准备时
onchunkuploadcompletingChunkResponse分块上传结束时
onfileuploadprogressFile, Progress文件上传进度中
onfileuploadendFile文件上传结束
onfileuploadcompletingFileResponse文件上传结束时
onfileuploadsuccessFile, FileResponse文件上传成功
onfileuploadcompletedFile, Status文件上传完成了
onfilestatuschangeFile, Status文件状态发生变化
onfilecancelFile文件退出

具体配置信息见https://github.com/uxcore/uxcore-uploadcore/blob/master/README.md.