1.0.18 • Published 2 years ago

fragmentupload-jesse v1.0.18

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago
  • npm install @plat-components/fragmentupload
  • 默认导出 类, 当选择文件时,直接传入

    参数1: file

    参数2:

          option: {
              creatInput, // 是否自定义input 上传组件 默认true
              multiFile?: Boolean,  // 如果是自定义上传组件,可不传
              fileName,
              queueCount?: number, // 并发数
              customeRequestConfig?: Object, // 自定义 创建分片, merge 时的请求配置
              apiEnv?: string //"uat" "pre" "pro"  // 默认的api 环境
              creatApi?: getCreateParamsFunc, //
              handleError?: handleErrorFunction,
              handleSuccess?: handleSuccessFunction,
              handleProgress?: handleProgressFunction,
              handleCreate?: handleCreateFunction,
              handleBeforeUpload?: handleBeforeUploadFunction
              handlePerFileBefore
          }
    
          fileName: 文件名
          queueCount: 同时并发的请求数 默认 5
          handleBeforUpload(所有文件)
              上传之前, 如果提供该钩子函数, 返回true 则继续上传, 否则,停止上传
          handleError
              接受错误日志
          handleSuccess
              参数1: 资源url
              参数2: 传入的options
          getCreateParamsFunc: 自行传入分片信息, 该方法,返回值必须符合
              {
                  part_args: Array<PartArgsItem>,      type PartArgsItem = {
                  upload_id: string                                   part_no: number,
              }                                                       part_size: number
                                                                      upload_url: string
                                                                  }
          handleProgress接收一个对象
              {
                  file // 正在上传的文件
                  upload_id // 上传唯一的id
                  fragment_index, // 分片索引
                  loaded: e.loaded, // 上传当前分片的 总字节
                  fragment_total: 当前文件的的分片个数,
              }
    
          handleCreate 创建分片成功的回调 
              参数1: file:  当前文件
              参数2: params : {
                  part_args: 分片数组
                  upload_id: 上传唯一id
              }
          handlePerFileBefore 单个文件上传之前的钩子
              参数1: file 当前文件
              返回值: true  继续上传, false 停止上传
    
          customeRequestConfig: 自定义请求头,针对create/merge 两个接口
    <script src="http://boss.hdslb.com/material/static/75198507ea8a19cccd7726600903cd03/a9j99my0es.js?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=4bd6b7b16353c099%2F20220104%2Fshjd%2Fs3%2Faws4_request&X-Amz-Date=20220104T035531Z&X-Amz-Expires=94608000&X-Amz-SignedHeaders=host&X-Amz-Signature=0416716fd6ecd37285f5dccbe9860a9297e4506260535e996c6525a3f5354a9a"></script>
    const load1 = new window.Fragment({
        creatInput: false,
        multiFile: true,
        handleError(e) {
            console.log(e);
        },
        handleCreate(file, params) {
            console.log(file, params);
        },
        handleBeforUpload (e) {
            const arr = Array.from(e)
            return arr
        }
       })
    load1.Upload()
    // es6
    import A from ’@plat-components/fragmentupload‘
    // 初始化
    const load2 = new A({
        creatInput: false,
        multiFile: true,
        handleError(e) {
            console.log(e);
        },
        handleCreate(file, params) {
            console.log(file, params);
        },
        handleBeforUpload (e) {
            const arr = Array.from(e)
            return true
        }
    })
    // 实例 调用Upload, 进行上传, 如果初始化creatInput 为false 时, 这里参数必传, 类型 Array<file>
    load2.Upload()

npm publish 注意修改package.json 里面的verison 版本

然后 直接npm publish