npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-upload-slice-file

v2.1.0

Published

一款前端简单的分片上传文件小项目,支持进度计算,队列提交,MD5校验

Downloads

14

Readme

Simple upload slice file

项目介绍

一款前端简单的分片上传文件小项目,不依赖jQuery,解决大文件上传过久,网络不稳定导致前功尽弃的问题。支持如下:

  • 设置切片大小
  • 进度计算
  • 队列提交
  • 队列控制
  • MD5校验
  • IE10及其他主流浏览器(因使用原生FormData对象)

历史版本

1.x

安装

(c)npm install simple-upload-slice-file -D

使用

Browser
    <script src="dist/simple-upload-slice-file.min.js"></script>

    new SimpleUploadSliceFile({
      //
      url: 'http://127.0.0.1:3000/upload',
      // 队列延迟发送,可用于调试,默认0(ms)
      delay: 0,
      // 切片大小(M),建议不要太小,默认10
      chunkSile: 20,
    })
      .appendHeader({
        header1: 'header 1',
      })
      .appendHeader({
        header2: 'header 2',
      })
      .appendData({
        data1: 'data 1',
      })
      .appendData({
        data2: 'data 12',
      })
      .addFile('file', document.querySelector('#file'))
      // .addFile('file', document.querySelector('#file')['files'])
      // .addFile('file', $('#file'))
      // .addFile('file', document.querySelector('#file')['files'][0])
      .addCallBack({
        // 上传进度
        progress: function (progress) {
          console.log('上传进度:' + progress);
        },
        // 每个切片完成后的回调,2.x由手动判断是否允许下一块进行提交,增加了灵活性
        sliceResponse: function (xhr, taskParam, queue) {
          // 原生 xhr 对象,根据对象信息判断是否进行下一个队列,status为4才回调
          // console.log('xhr');
          // console.log(xhr);
          // 任务参数
          // console.log('taskParam');
          // console.log(taskParam);
          // console.log('queue');
          // console.log(queue);
          // queue 使用方法 https://github.com/8696/js-queue
          // 例1:
          if (xhr.status === 200) {
            var responseData = typeof xhr.responseText === 'string' ? JSON.parse(xhr.responseText) : xhr.responseText;
            if (responseData.code === 0) {
              // 继续提交
              queue.next();
            } else {
              // 重新提交当前块
              queue.again();
            }
          } else {
            // 重新提交当前块
            queue.again();
          }
        },
        // 队列中的最后一次响应
        lastResponse: function (data, taskParam) {
          console.log(data);
        }
      })
      .send();

    // 获取 MD5
    SimpleUploadSliceFile.getMD5({
      // file: $('#file'),
      // file: document.querySelector('#file'),
      // file:document.querySelector('#file')['files'],
      file: document.querySelector('#file')['files'][0],
      success: function (res) {
        console.log('md5:');
        console.log(res);
      },
      progress: function (res) {
        // console.log(res);
      },
      complete: function (res) {
        // console.log(res);
      },
      error: function (res) {
        // console.log(res);
      }
    });
vue

    import SimpleUploadSliceFile from 'simple-upload-slice-file';
    
    new SimpleUploadSliceFile.addFile().send();