Vue使用七牛云上传的实例

先上代码:

	//安装相关的依赖
	npm install qiniu-js --save
	
	//引用
	import * as qiniu from 'qiniu-js';
	Vue.use(qiniu);
	
	// plupload 我这里是引用的cdn,最好是下载下来或是进行安装
	// https://cdn.staticfile.org/plupload/2.1.9/plupload.full.min.js
	<span id='pickfiles' >上传资料</span>
//初始化 
	Qiniu.uploader({
        runtimes: 'html5,flash,html4',
        browse_button: 'pickfiles',
        chunk_size: '8mb',
        bucket: " ",//命名空间
        uptoken:this.token, 
        //  JSON.stringify(that.token),
        uptoken_url: '',//获取token的地址
        unique_names: false,  
        save_key: false,//可以保存名字???
        domain: '',//七牛云地址
        get_new_uptoken: true,
        auto_start: true,
        // max_retries: 3,
        filters: {
          max_file_size: '500mb',
          prevent_duplicates: false
          // Specify what files to browse for
          // mime_types: [
          //     {title : 'apk files', extensions : 'apk'} // 限定apk后缀上传格式上传
          // ]
        },
        init: {
          'FilesAdded': (up, files) => {
              console.log('文件就绪', files);
              this.fileName = files[0].name
          },
          BeforeUpload: (up, file) => {
            console.log('上传之前', file);
          },
          UploadProgress: (up, file) => {
            console.log('上传中 file',file);
            console.log(file.target_name)
            this.progress = file.percent + '%';
          },
          FileUploaded: (up, file, info) => {
            console.log('文件上传完毕')
            this.$toast("上传成功")
            this.success = true;
            this.$http.post('/uac/auth/pcb/updateMaterialUrl',{orderId:this.$route.query.id,materialUrl:this.fileName,id:this.$route.query.msgId}).then((res)=>{
              console.log(res);
              console.log(this.$route.query.id)
            })
          },
          Error: (up, err, errTip) => {
            console.log('上传失败', err);
            this.$toast("上传失败")
          },
          //设置key
          Key: (up, file) => {
            var key = file.name
            return key;
          }
        }
      });
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值