JSPM

file-slices

1.0.3
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • 0
    • Score
      100M100P100Q25165F
    • License ISC

    前端文件分片

    Package Exports

    • file-slices
    • file-slices/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-slices) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    得到实例对象

    var myfile = new Fileslice()

    传递配置

    var myfile = new Fileslice({
     * 
     * @url 请求地址
     * @file 文件
     * @filename 想保存的文件名包含后缀
     * @padding 上传中回调
     * @success 成功回调
     * @fail 失败回调
     * @chunk 每一刀大小 (可选)
    })

    实例方法

      /** 执行上传方法 
       * 
       * @ object{
       * 限制类型 
        'video/mp4': 'mp4'
      }
      值为空代表都可以上传
       */
    myfile.fileslice()
    或
      myfile.fileslice({
        'video/mp4': 'mp4'
      })

    完整代码

    HTML

    <body>
      <input id="file" type="file">
      <button class="send">上传</button>
      <script type="module" src="./index.js"></script>
    </body>

    JS

    let ofile = document.querySelector("#file");
    let osend = document.querySelector(".send");
    osend.addEventListener("click", function (e) {
      let file = ofile.files[0]
      /**
     * 
     * @url 请求地址
     * @file 文件
     * @filename 文件名
     * @padding 上传中回调
     * @success 成功回调
     * @fail 失败回调
     * @chunk 每一刀大小
     */
      let myfile = new Fileslice({
        url: '/uploadBig',
        file,
        chunk: 256 * 1024,
        filename: new Date().getTime() + '_' + file.name,
        padding: function (value) {
          console.log(value);
        },
        success: function (data) {
          console.log(data);
        },
        fail: function (error) {
          console.log(error);
        }
      })
      /** 执行上传方法 
       * 
       * @ object{
       * 限制类型 
        'video/mp4': 'mp4'
      }
      值为空代表都可以上传
       */
    `  myfile.fileslice({
        'video/mp4': 'mp4'
      })`
    }, false)