zoukankan      html  css  js  c++  java
  • 阿里云OSS 服务端签名后直传之分片上传(结合element-ui的upload组件)

    分片上传(结合element-ui的upload组件实现自定义上传)

    async uploadFree(content){
         let data = await this.getOssToken();    //后台返回的OSS秘钥等等
         let client = new OSS({
             region: data.region,
             accessKeyId: data.AccessKeyId,
             accessKeySecret: data.AccessKeySecret,
             stsToken: data.SecurityToken,
             bucket: data.bucketName
         });
         try {
            let result = await client.multipartUpload(content.file.name, content.file, {
                progress: async function (p) {//这是上传进度条
                    content.onProgress({percent: parseInt(p * 100)+'%', returnValue: true });
                }
         });
        return (content.file['response'] = [result].map(curr =>{//on-change回调的参数
            return {
                code: curr.res.status,
                name: content.file.name,
                data: curr.res.requestUrls[0].split('?')[0]
            }
        })[0]);
    
        } catch (e) {
             console.log(e)
            if (e.code === 'ConnectionTimeoutError') {
                content.onError('视频上传超时')
                throw "视频上传超时!";
            }else{
                content.onError('视频上传失败')
            }
        }
    }

    官方文档: 传送门

  • 相关阅读:
    SpringMVC 下载本地文件
    Spring MVC 自定义转换器
    Struts,Hibernate,Spring经典面试题
    SpingMVC 执行的流程
    SpringMVC 应用配置
    SpringMVC特点
    Struts2学习
    mysql免安装配置
    mysql免安装版设置密码
    《金色梦乡》金句摘抄(六)
  • 原文地址:https://www.cnblogs.com/guojikun/p/9685143.html
Copyright © 2011-2022 走看看