首页 > 其他分享 >el-upload分片上传到七牛

el-upload分片上传到七牛

时间:2024-02-07 15:34:50浏览次数:19  
标签:el option res upload fileList 七牛 uploadForm file 上传

参考: https://blog.csdn.net/So_cute_girl/article/details/118606647

需要自定义上传方法http-request,用七牛的分片上传

<template>
  <el-upload drag :limit="1" action="https://up.qiniup.com" :multiple="false"
    accept=".mp4" :data="uploadForm" :file-list="fileListVideo" :before-upload="beforeUpload"
    :on-exceed="onExceedUploadVideo" :on-remove="onRemoveUploadVideo" :on-success="onSuccessUploadVideo"
    :on-change="onChangeUploadVideo" :http-request="uploadHttpRequestVideo">
    <i class="el-icon-upload" />
    <div class="el-upload__text">
      将视频拖到此处,或
      <em>点击上传</em>
    </div>
    <div slot="tip" class="tip-text">
      上传一个,视频大小不超过1.5G,支持mp4格式。
    </div>
  </el-upload>
</template>

<script>

import { getQiniuToken } from "@/utils/commons";
import * as qiniu from "qiniu-js";

export default {
  data () {
    return {
      fileList: [],
      uploadForm: {
        token: "",
      },
      maxSize: 1.5 * 1024 * 1024 * 1024,
      subscription: null
    };
  },
  mounted () {
    this.getQiniuToken()
  },
  beforeUnmount () {
    this.subscription && this.subscription.unsubscribe()
  },
  methods: {
    async getQiniuToken () {
      this.uploadForm.token = await getQiniuToken();
    },
    beforeUpload (file) {
      // 重命名
      this.uploadForm.key = `${file.uid}_${Math.floor(Math.random() * 10000)}.${file.name.split('.').pop()}`
    },
    onExceedUpload () {
      // 超过了上传数量
      this.$message({
        message: '最多上传一个视频',
        type: "warning"
      });
    },
    onRemoveUpload (file, fileList) {
      // 删除
      this.fileList = fileList;
    },
    onSuccessUpload (res, file) {
      // 上传成功
    },
    onChangeUpload (file, fileList) {
      // 文件大小
      if (file.size > this.maxSize) {
        this.$message({
          message: '文件超过1.5G',
          type: "error"
        });
        return false
      }
      this.fileList = fileList;
    },
    uploadHttpRequest (option) {
      const observable = qiniu.upload(option.file, this.uploadForm.key, this.uploadForm.token)
      this.subscription = observable.subscribe({
        next (res) {
          option.onProgress({ percent: res.total.percent })
        },
        error (err) {
          option.onError(err)
        },
        complete (res) {
          option.onSuccess(res)
        }
      })
      return this.subscription
    }
  }
};
</script>

 

标签:el,option,res,upload,fileList,七牛,uploadForm,file,上传
From: https://www.cnblogs.com/liuyongfa/p/18010965

相关文章

  • 43、excel快速填充序列号,删除行时序号自动跟上
    平时填充序号的做法:首先在第1、2行输入1、2,然后用手往下拖动,填充后面的行,缺点:当我删除一行时,后面的序号不会自动按顺序填充上 解决方法:1、在excel上选中A6单元格,然后左上角输入A6:A110,按【回车】键2、直接输入【=ROW()-1】,再按【ctrl+回车】键盘就可以了缺点:由于公......
  • P9501 RiOI-2 likely
    好好好好好题\(T\)组数据,给定\(n,m,k\),求所有\(2^n\)个大小为\(n\)的由\(\pm1\)组成的有标号环\(a_{0\dotsn-1}\)中,有多少个满足\(\sum_{i=0}^{n-1}\prod_{j=0}^{m-1}a_{(i+j)\\bmod\n}=k\)。对\(998244353\)取模。\(1\leT\le10,2\len,\sumn\le5\tim......
  • Codeforces-Hello-2024-Round
    比赛链接A.WalletExchange签到,某个人操作的时候只要一方有金币就行,所以最终赢的应该是拿到最后一个硬币的人,当\(a+b\equiv1\pmod2\)的时候Alice获胜,否则Bob获胜。时间复杂度\(\mathcal{O}(1)\)。codeforA#include<bits/stdc++.h>usingnamespacestd;inli......
  • [Ngbatis源码学习] Ngbatis 源码学习之资源加载器 DaoResourceLoader
    Ngbatis源码阅读之资源加载器DaoResourceLoaderDaoResourceLoader是Ngbatis的资源文件加载器,扩展自MapperResourceLoader。本篇文章主要分析这两个类。1.相关类MapperResourceLoaderDaoResourceLoader2.MapperResourceLoader在介绍DaoResourceLoader之前有必要......
  • [Violation ] Added non-passive event listener to ascroll- blocking ‘mousewheel
    [Violation]Addednon-passiveeventlistenertoascroll-blocking'mousewheel’eventConsidermarkingeventhandleras’passive’tomakethepagemoreresponsive.--控制台报错解决方法这个错误翻译过来的的意思就是:[违规]在ascroll中添加了非被动事件侦听器-阻......
  • datetime.date + datetime.timedelta 结果仍然是 datetime.date 因而不能与时间进行比
    importpandasaspdimportdatetimedefmain():foo=pd.Timestamp.now()bar=datetime.date.today()+datetime.timedelta(days=-1)res=bar+datetime.timedelta(hours=24)print(res,type(res))if__name__=='__main__':ma......
  • pandas.Timedelta(days=1) 可以 与 datetime.timedelta(days=1) 效果一致
    pandas.Timedelta(days=1)可以与datetime.timedelta(days=1)效果一致https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Timedelta.html#pandas-timedelta但pandas.Timedelta可以有其他写法......
  • PowerShell中,可以使用以下命令来发送和接收TCP数据 发送IPv4 TCP数据 接收IPv4 TCP
    在PowerShell中,可以使用以下命令来发送和接收TCP数据:发送IPv4TCP数据:CopyCode$remoteIPAddress="192.168.0.1"$remotePort=80$tcpClient=New-ObjectSystem.Net.Sockets.TcpClient($remoteIPAddress,$remotePort)$networkStream=$tcpClient.GetStream()$bytes......
  • PowerShell 的 Get-FileHash 命令查询一个文件的所有上述哈希值(假设是 SHA256, MD5, S
    PowerShell是一种跨平台的任务自动化解决方案,包含一个命令行外壳、脚本语言和配置管理框架。PowerShell提供了用于计算文件哈希值的内置命令Get-FileHash。Get-FileHash命令可以用来计算文件的哈希值,支持多种哈希算法。,Get-FileHash支持以下几种哈希算法:SHA256:默认算法,提......
  • #排列组合#CF1550D Excellent Arrays
    洛谷传送门CF1550D分析对于excellent的\(a\)来说\(|a_i-i|=x\)的值是固定的,考虑枚举它一半正一半负时函数值是最大的,当\(n\)为奇数时要分为两种情况(不过可以通过杨辉三角合并)问题是,由于\(l,r\)的范围,并不能做到所有位置都能可正可负,不过不超过\(mn=\min\{1-l,r-n\}......