npm install qiniu-js
所用页面
const qiniu = require('qiniu-js') // or import * as qiniu from 'qiniu-js'
upLoad() { let that = this; let fileName = this.imgData[0].name; let key = new Date().getTime(); // 上传ket let token = that.uptoken; const putExtra = { fname: "", params: {}, mimeType: null }; const config = { region:'', chunkSize:10, forceDirect:false, }; const headers = qiniu.getHeadersForChunkUpload(that.uptoken); const observable = qiniu.upload( this.imgData[0].raw,//文件数组 key, token, putExtra, config );const observer = { next: response => { if(Math.floor(response.total.percent)>=100){ // clearInterval(that.Interval) console.log(Math.floor(response.total.percent)) }// console.log(response); // 上传进度'+Math.floor(response.total.percent)+'%' }, error: err => { // 失败 this.$message.error("上传失败" + err.message); }, complete: response => { console.log(response); } }; observable.subscribe(observer); // 上传开始 },
官方文档地址
https://developer.qiniu.com/kodo/sdk/javascript