JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q43707F
  • License MIT

file-slice-upload

Package Exports

  • file-slice-upload
  • file-slice-upload/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (file-slice-upload) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

📄 File-Slice-Upload

English

快速开始

1. 安装

  • 使用 npm 安装
npm install file-slice-upload
  • 使用 yarn 安装
yarn add file-slice-upload

2. 使用 file-slice-upload 上传文件碎片

import fileUpload from 'file-slice-upload'
fileUpload()
.file(youFile, '1MB')
.uploadFunc(async(chunk)=>{
  const success = await postChunkFile(chunk)
  return success   /* 返回 true 将会上传下一个文件碎片 */
})
.start()

🔥🔥🔥 特点

  1. 轻松控制上传流程, 让你只需专注上传逻辑!
  2. 友好、易读的 api .start() .stop() .continue()...
  3. 支持事件 start finish stop progress error...
  4. 轻量
  5. 不依赖任何第三方库
  6. 使用 typescript 编码, 代码提示良好

API文档

默认导出

工厂函数,返回fileUpload 实例

参数 类型 必传 说明
并发数 number - (0, 8] false 每轮发送n个文件碎片

fileUpload类

  1. fileUpload.file(file, chunkSize, chunkName?) => this
参数名 类型 必传 说明
file File true 分片上传的文件
chunkSize String true 文件碎片大小,传入'200KB' '1MB' '2M' 等格式的字符串
chunkName (file: 文件, index: 碎片序列) => 文件碎片的名称 false 传入函数,该函数返回的字符串作为文件碎片的name属性值
  1. fileUpload.uploadFunc(ajax) => this
参数名 类型 必传 说明
ajax (chunk: File | File[], index: number, chunks: File[] | File[][]) => boolean true 上传文件碎片的函数,返回true就上传下一个碎片
  1. fileUpload.start() => this 开始上传

  2. fileUpload.stop() => this 暂停上传

  3. fileUpload.continue() => this 继续上传

  4. fileUpload.on(eventName, cb) => this 监听上传事件

eventName 说明 cb函数类型
start 开始上传 () => void
finish 上传完成 () => void
continue 继续上传 () => void
progress 上传进度 ({done: number, all: number}) => void
chunk-uploaded 分片上传成功 ({chunk: File, index: number, chunks: File[] }) => void
error 上传失败 () => void
  1. fileUpload.off(eventName, cb) => this 取消事件注册

demo

  1. live-demo