七牛云服务器的储存区域

存储区域 地域简称 上传域名
华东 z0 服务器端上传:http(s)://up.qiniup.com
华东 z0 客户端上传: http(s)://upload.qiniup.com
华北 z1 服务器端上传:http(s)://up-z1.qiniup.com
华北 z1 客户端上传: http(s)://upload-z1.qiniup.com
华南 z2 服务器端上传:http(s)://up-z2.qiniup.com
华南 z2 客户端上传: http(s)://upload-z2.qiniup.com
北美 na0 服务器端上传:http(s)://up-na0.qiniup.com
北美 na0 客户端上传: http(s)://upload-na0.qiniup.com
东南亚 as0 服务器端上传:http(s)://up-as0.qiniup.com
东南亚 as0 客户端上传: http(s)://upload-as0.qiniup.com

<template>
<div class="container">
<div class="title"><h2>ElementUI的Upload上传图片到七牛云</h2></div>
<el-upload
class="upload-demo"
drag
:action="upload_qiniu_url"
:show-file-list="false"
:on-success="handleAvatarSuccess"
:on-error="handleError"
:before-upload="beforeAvatarUpload"
:data="qiniuData">
<img v-if="imageUrl" :src="imageUrl" class="avatar">
<div v-else class="el-default">
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
</div>
<div class="el-upload__tip" slot="tip">只能上传jpg/png文件,且不超过2MB</div>
</el-upload>
</div>
</template> <script>
export default {
data() {
return {
qiniuData: {
key: "",
token: ""
},
// 七牛云上传储存区域的上传域名(华东、华北、华南、北美、东南亚)
upload_qiniu_url: "http://upload-z1.qiniup.com",
// 七牛云返回储存图片的子域名
upload_qiniu_addr: "http://abc.clouddn.com/",
imageUrl: "",
Global: {
dataUrl: 'http://yoursite.com'
}
};
},
created() {
this.getQiniuToken();
},
methods: {
getQiniuToken: function() {
const _this = this;
this.$axios
.post(this.Global.dataUrl + "/qiniu/uploadToken")
.then(function(res) {
console.log(res);
if (res.data.success) {
_this.qiniuData.token = res.data.result;
} else {
_this.$message({
message: res.data.info,
duration: 2000,
type: "warning"
});
}
});
},
beforeAvatarUpload: function(file) {
this.qiniuData.key = file.name;
const isJPG = file.type === "image/jpeg";
const isPNG = file.type === "image/png";
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isJPG && !isPNG) {
this.$message.error("图片只能是 JPG/PNG 格式!");
return false;
}
if (!isLt2M) {
this.$message.error("图片大小不能超过 2MB!");
return false;
}
},
handleAvatarSuccess: function(res, file) {
this.imageUrl = this.upload_qiniu_addr + res.key;
console.log(this.imageUrl);
},
handleError: function(res) {
this.$message({
message: "上传失败",
duration: 2000,
type: "warning"
});
}
}
};
</script> <style scode>
.title{
margin:90px 0 40px 0;
}
.el-default .el-icon-upload {
margin-top: 125px;
}
.el-upload-dragger {
width: 350px;
height: 350px;
}
.avatar {
width: 350px;
height: 350px;
display: block;
}
</style>

来源:https://segmentfault.com/a/1190000016309473

ElementUI的Upload上传,配合七牛云储存图片的更多相关文章

  1. 阿里云CentOS自动备份MySql 8.0并上传至七牛云

    本文主要介绍一下阿里云CentOS7下如何对MySql 8.0数据库进行自动备份,并使用.NET Core 将备份文件上传至七牛云存储上,并对整个过程所踩的坑加以记录. 环境.工具.准备工作 服务器: ...

  2. 利用cropper插件裁剪本地图片,然后将裁剪过后的base64图片上传至七牛云空间

    现在做的项目需要做一些图片处理,由于时间赶急,之前我便没有处理图片,直接将图片放在input[type=file]里面,以文件的形式提交给后台,这样做简直就是最低级的做法,之后各种问题便出来了,人物头 ...

  3. .Net Core实现将文件上传到七牛云存储

    功能:将图片上传到七牛云存储 准备工作 注册七牛账号,提交实名认证(基本上1天内内审核通过) 登录七牛后台->对象存储->新建空间 (基本概念:https://developer.qini ...

  4. laravel7文件上传至七牛云并保存在本地图片

    HTML代码: <form class="layui-form" action="{{route('doctor.store')}}" method=&q ...

  5. 微信小程序文件上传至七牛云(laravel7)

    1 wxml: <view> <form bindsubmit="dopost"> <view> <label>真实姓名</l ...

  6. vue图片上传到七牛云

    代码: <template> <div class="upload-info"> <div> <el-upload class=" ...

  7. Element-UI中Upload上传文件前端缓存处理

    Element-UI对于文件上传组件的功能点着重于文件传递到后台处理,所以要求action为必填属性.但是如果需要读取本地文件并在前端直接处理,文件就没有必要传递到后台,比如在本地打开一个JSON文件 ...

  8. Tp3.1 文件上传到七牛云

    TP3.1 中不支持Composer 就无法用composer 安装 下载历史的SDK https://github.com/qiniu/php-sdk/releases/tag/v7.0.8 下载下 ...

  9. tp5 webupload文件上传至七牛云

    1:composer安装: composer require qiniu/php-sdk 2: 配置使用: 在tp5.1的配置文件app.php中配置七牛云的参数 'qiniu' => [ 'a ...

随机推荐

  1. AtCoder Regular Contest 095E - Symmetric Grid

    $n \leq 12,m \leq 12$,$n$行$m$列小写字母,现可做无数次操作:交换两行:交换两列.问是否有可能把他变成中心对称的. 没有去想分组枚举的复杂度QAQ 行和列的操作顺序是随意的. ...

  2. Linux 下MySQL 安装与卸载

    这个写的比较好:http://www.cnblogs.com/starof/p/4680083.html 2.卸载系统自带的Mariadb rpm -qa|grep mariadb         / ...

  3. 487. Max Consecutive Ones II

    Given a binary array, find the maximum number of consecutive 1s in this array if you can flip at mos ...

  4. Ajax 实现文件的下载

    JQuery的ajax函数的返回类型只有xml.text.json.html等类型,没有“流”类型,所以我们要实现ajax下载,不能够使用相应的ajax函数进行文件下载.但可以用js生成一个form, ...

  5. R读数据stringsAsFactors=F,存数据时row.names = F

    stringsAsFactors=F   以前在r里读数据,经常把character读成factor,还得费半天劲把它转回来,尤其是把factor转成numeric还没有那么直接.例如: dat< ...

  6. (4)Swing布局

    一.FlowLayout-流布局 新增第一个组件后默认在第一行的居中位置,之后 组件按照加入的先后顺序按照设置的对齐方式从左向右排列 二.borderLayout-边框布局 容器划分为东.西.南.北. ...

  7. 接阿里云oss有感

    看API,从头细看到尾,在这个过程中一定会找到你要找的东西.

  8. MVC RPC SOA 和微服务架构的区别

    MVC RPC SOA 微服务架构的区别 单体架构 MVC(Model View Controller) M是指业务模型,V是指用户界面,C则是控制器,使用MVC的目的是将M和V的实现代码分离,从而使 ...

  9. Ubuntu下Deb软件包相关安装与卸载

    安装deb软件包 sudo dpkg -i xxx.deb 删除软件包 sudo dpkg -r xxx.deb 连同配置文件一起删除 sudo dpkg -r --purge xxx.deb 查看软 ...

  10. HTML5 这些你全知道吗?

    今天心情烦躁,搭建个论坛各种失败,Laravel.React也学不进去,于是就复习复习学过的.记录一下很少用的东西. 代码摘抄于W3C菜鸟教程HTML5手册 # 定义文本方向 <element ...