当前位置:网站首页>上传七牛云的方法
上传七牛云的方法
2022-07-27 05:02:00 【pink_Pig___】
注册一个用户
保存密钥

新建空间默认为华南必须认证身份才行
把空间名记录下来
点击开发者中心
点击对象存储
保存地址
获取域名

后端逻辑
from qiniu import Auth
# 七牛云的密钥
AK1:"wRw1Dl-H8PAb_uAuEI2F5TDx5HSsDPktNM3zpwbo"
SK1:"Dxx2HWInPnfJj9pcTw2BbxvU1D9qonKEJHyttgqX"
AK2:"fgQoD2J8Dz-t-XL0-zXLYvROfjBLF6mJ7eDqO_wb"
SK2:"EDF6xq5NgHQMclFMaw6WOdjSxc3Yluc84d7hDRDr"
存储空间名称:"wangzhiyi1"
def gen_token():
q = Auth(ak, sk)
# 生成七牛的token
token = q.upload_token(bucket='p6123', expires=3600)
return token
# 七牛token的视图
class QiniuTokenView(APIView):
def get(self, request):
# 成功七牛token
token = gen_token()
return Response({
'code': 200,
'msg': '七牛云token生成成功',
'token': token
})
前端逻辑
<el-form-item label="商品图片" prop="image">
<!-- :action="保存的地址,把(s)取掉" -->
<el-upload :action="'http://up-z2.qiniup.com'" :on-success="uploadSuccess" :data="upload_data" :on-error="uploadError" >
<el-button size="small" type="primary">点击选择图片</el-button>
</el-upload>
</el-form-item>
mounted() {
this.axios
.get("v1/goods/qiniuToken/", {
headers: {
Authorization: "JWT " + token,
},
responseType: "json",
})
.then((dat) => {
// console.log("token>>>",dat.data);
this.upload_data.token = dat.data.token;
})
.catch((err) => {
console.log(err.response);
});
},
上传成功后保存七牛云图片地址
uploadSuccess(res, files) {
console.log("上传的图片响应:", res);
this.PicturesForm.image = 'http://' + '自己的域名' + '/' + res.key
console.log("'上传成功',>>>", this.PicturesForm.image);
},
边栏推荐
- B1028 census
- JVM Part 1: memory and garbage collection part 14 -- garbage collector
- Critical path principle
- B1021 个位数统计
- JVM part I: memory and garbage collection part II -- class loading subsystem
- Three waiting methods of selenium and three processing methods of alert pop-up
- Two dimensional array summation exercise
- File processing (IO)
- The difference between strlen and sizeof
- torch中乘法整理,*&torch.mul()&torch.mv()&torch.mm()&torch.dot()&@&torch.mutmal()
猜你喜欢

JVM Part 1: memory and garbage collection part 6 -- runtime data area local method & local method stack

用户的管理-限制

Bean的生命周期&&依赖注入*依赖自动装配

Prime number screening (Ehrlich sieve method, interval sieve method, Euler sieve method)

JVM Part 1: memory and garbage collection part 10 - runtime data area - direct memory

SQL数据库→约束→设计→多表查询→事务

Sparse array → saving and continuation of Gobang

Integrate SSM

Explore the mysteries of the security, intelligence and performance of the universal altek platform!

JVM上篇:内存与垃圾回收篇九--运行时数据区-对象的实例化,内存布局与访问定位
随机推荐
JVM上篇:内存与垃圾回收篇三--运行时数据区-概述及线程
如何快速上手强化学习?
JVM上篇:内存与垃圾回收篇六--运行时数据区-本地方法&本地方法栈
numpy 数据类型转化
Solution and principle analysis of feign call missing request header
redis持久化
SSM framework integration
LocalDateTime和ZonedDateTime
B1031 check ID card
Differences among bio, NiO and AIO
Shell course summary
cookie增删改查和异常
笔记系列之docker安装Postgresql 14
During its low-level period, this slave edge causes the instruction number to make a corresponding model
JVM上篇:内存与垃圾回收篇二--类加载子系统
辗转相除法
B1025 reverse linked list*******
素数筛选(埃氏筛法,区间筛法,欧拉筛法)
B1031 查验身份证
Bean's life cycle & dependency injection * dependency auto assembly