当前位置:网站首页>上传七牛云的方法
上传七牛云的方法
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);
},
边栏推荐
猜你喜欢

JVM Part 1: memory and garbage collection part 9 - runtime data area - object instantiation, memory layout and access location

Could not autowire. No beans of ‘userMapper‘ type found.

简化JDBC的MyBits框架

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

String class

李宏毅机器学习组队学习打卡活动day03---误差和梯度下降

The difference between strlen and sizeof

数据库设计——关系数据理论(超详细)

JVM上篇:内存与垃圾回收篇六--运行时数据区-本地方法&本地方法栈

Rolling Division
随机推荐
JVM Part 1: memory and garbage collection part 10 - runtime data area - direct memory
The provision of operation and maintenance manager is significantly affected, and, for example, it is like an eep command
SQL database → constraint → design → multi table query → transaction
Idea remote debugging
322 coin change of leetcode
如何快速上手强化学习?
numpy 数据类型转化
B1026 程序运行时间
李宏毅机器学习组队学习打卡活动day06---卷积神经网络
Sparse array → saving and continuation of Gobang
LocalDateTime和ZonedDateTime
2021 OWASP top 6-10 collection
B1024 科学计数法
How to store the startprocessinstancebykey method in acticiti in the variable table
LeetCode之268.Missing number
如何查看导师的评价
B1031 check ID card
A math problem cost the chip giant $500million
求组合数(最强优化)
BIO、NIO、AIO区别