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

a06-upload-sdk

v1.0.5

Published

a upload jssdk support resume

Downloads

2

Readme

a06-upload-sdk 上传sdk

js实现的上传文件sdk,支持断点续传

安装

npm install a06-upload-sdk

加载方式

支持全局引入,commonjs,esm三种加载方式

//global
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
const upload = new sdk({})


commonjs
const UploadSdk = require('@/sdk').default

esm
import UploadSdk from '@/sdk'

使用

以esm加载方式为例,代码如下

params结构

    // {
    //   ext: 'png'
    //   hash: 'xxxx'
    //   id: 'tid_1390'
    //   name: 'TIM截图20180725012456'
    //   size: 206845
    //   splitCount: 0
    //   type: 'image/png'
    // }
import UploadSdk from '@/sdk'
  
const sdk = new UploadSdk({
  //上传接口,必传
  uploadUrl: 'http://127.0.0.1:8768/upload',  
  //是否开启多文件选择,默认为false
  multiple: true,
  //设置允许上传的文件类型,默认为*全部
  accepts: ['gif','png'],
  //开始上传文件之前的钩子,不关心可以不传,允许你根据你的业务情况终止此次上传,
  //params为回调参数,
  //next用来决定是否继续往下执行上传,不调用则终止此次上传
  beforeHook (params, next) {
    //你的业务代码,决定是否next,next中的参数是切片索引,如果不启用断点续传那么
    //直接传0或者不传.如果启用断点上传那么这里传入当前上传到哪个分片
    //ajax获取服务端保存的分片信息,比如服务端返回当前这个文件已经上传到片段5,那么
    //next(5)
  },
  //input file的name值,默认file
  name: 'file',
  //是否开始断点续传,默认true
  resume: true,
  //自定义参数,你的业务字段,如鉴权等,这些参数会在调用upload接口的时候一起传上去
  exParams: {
    token: 'xxxxxxxxxxooooooooo',
    test: 1
  }
})

//调用选择文件
sdk.select()
//暂停指定上传任务
sdk.pauseTask(tid)
//恢复指定上传任务
sdk.resumeTask(tid)
//删除指定上传任务
sdk.removeTask(tid)

//添加任务事件,会在beforeHook执行过后,上传开始之前触发
sdk.on('addTask', function (data) {
  console.log('addTask', data)
  // {
  //   ext: "png"
  //   hash: "2f1e861d563b5782f9dcd23ac8b98a38"
  //   id: "tid_1321"
  //   name: "TIM截图20180725012456"
  //   size: 206845
  //   splitCount: 0
  //   type: "image/png"
  // }
})
//上传进度事件
sdk.on('progress', function (data) {
  console.log('progress', data)
  // {
  //   ext: "png"
  //   hash: "2f1e861d563b5782f9dcd23ac8b98a38"
  //   id: "tid_1619"
  //   loaded: 206845
  //   name: "TIM截图20180725012456"
  //   percent: "100.00%"
  //   size: 206845
  //   splitCount: 0
  //   total: 206845
  //   type: "image/png"
  // }
})
//上传完毕事件
sdk.on('complete', function (data) {
  console.log('complete', data)
  // {
  //   ext: 'png'
  //   hash: null
  //   id: 'tid_1894'
  //   name: 'TIM截图20180725012456'
  //   size: 206845
  //   splitCount: 0
  //   type: 'image/png'
  // }
})
//发生错误事件,用于捕获sdk抛出的异常
sdk.on('error', function (err) {
  console.log('error', err)
})

帮助

该sdk编写了配套的服务端demo(nodejs实现),方便你使用此sdk进行本地实验.,github地址

License

The MIT license.