simple-uploader.js菜鸟教程网_一个Js上传库

simple-uploader.js菜鸟教程网

GitHub:https://github.com/simple-uploader/Uploader

simple-uploader.js菜鸟教程网_一个Js上传库

简介描述:一个Js上传库

simple-uploader.js(也称 Uploader) 是一个上传库,支持多并发上传,文件夹、拖拽、可暂停继续、秒传、分块上传、出错自动重传、手工重传、进度、剩余时间、上传速度等特性;该上传库依赖 HTML5 File API。由于是分块上传,所以依赖文件的分块 API,所以受限于此浏览器支持程度为:Firefox 4+, Chrome 11+, Safari 6+ and Internet Explorer 10+。

安装

npm install simple-uploader.js

使用

创建一个 Uploader 实例:

var uploader = new Uploader({
  target: '/api/photo/redeem-upload-token', 
  query: { upload_token: 'my_token' }
})
// 如果不支持 需要降级的地方
if (!uploader.support) location.href = '/some-old-crappy-uploader'

如果想要选择文件或者拖拽文件的话,你可以通过如下两个 API 来指定哪些 DOM 节点:

uploader.assignBrowse(document.getElementById('browseButton'))
uploader.assignDrop(document.getElementById('dropTarget'))

实例化后你还可以选择监听一些事件:

// 文件添加 单个文件
uploader.on('fileAdded', function (file, event) {
  console.log(file, event)
})
// 单个文件上传成功
uploader.on('fileSuccess', function (rootFile, file, message) {
  console.log(rootFile, file, message)
})
// 根下的单个文件(文件夹)上传完成
uploader.on('fileComplete', function (rootFile) {
  console.log(rootFile)
})
// 某个文件上传失败了
uploader.on('fileError', function (rootFile, file, message) {
  console.log(rootFile, file, message)
})

海计划公众号
(0)
上一篇 2020/03/11 07:00
下一篇 2020/03/11 07:00

您可能感兴趣的内容