前端实现阿里云oss直传 进度条

 // img 文件夹下  obj.file.name 文件的名字 obj.file文件对象
      client.multipartUpload('img/' + obj.file.name, obj.file,
        {
          // 进度条的配置项
          progress: function(percentage) { // 获取进度条的值
            console.log(percentage)
            // console.log(p * 100)
            this.percent = percentage * 100
          },
          // 每传输完一个分片 进度条会走一个百分比 不设置的话由于partsize过大 可能导致很长时间进度条都看不到效果
          partSize: 102400 // 指定上传的每个分片的大小,范围为100 KB~5 GB。单个分片默认大小为1 * 1024 * 1024(即1 MB)
        }
      ).then(response => {
        console.log(response)
        if (response.res.status === 200) {
          console.log('上传了')
          this.imageUrl = response.url // 把上传后的地址给img
          this.showProgress = false
        }
      }).catch(function(err) {
        console.error('error: ', err)
      })

 

posted @ 2022-06-08 16:59  luckylou  阅读(553)  评论(0编辑  收藏  举报