当前位置:网站首页>Flask encapsulates seven cattle cloud
Flask encapsulates seven cattle cloud
2022-07-26 18:36:00 【ZXY_ lucky】
Why encapsulate ?
When we write views on the back end , It is often used to upload pictures to qiniu cloud , To save time , Reduce code reuse problems , Encapsulate the seven cattle cloud code , Call directly when using !
1. The configuration file
Put the parameters used by seven cows in the configuration file , Avoid modifying
2. encapsulation
from qiniu import Auth,put_file
from flask import current_app
class QiniuTool():
def __init__(self):
ak = current_app.config.get('QINIU_AK')
sk = current_app.config.get('QINIU_SK')
self.q = Auth(ak,sk)
self.bucket_name = current_app.config.get('QINIU_BUCKET')
def upload(self,localfilepath,newfilename):
''' Seven cattle cloud upload pictures :param localfilepath: Local file address :param newfilename: The file name after uploading :return: '''
token = self.q.upload_token(self.bucket_name,newfilename,3600)
res = put_file(token,newfilename,localfilepath,version='v2')
print(token)
if res[0]['key'] == newfilename:
return newfilename
else:
return False
边栏推荐
猜你喜欢

J9数字论:如何避免踩雷多头陷阱?

Kindergarten system based on SSM
![[a little knowledge] thread pool](/img/47/7296e47b53e728d2d3b9db198243f4.png)
[a little knowledge] thread pool

立即报名 | 云原生技术交流 Meetup 广州站已开启,8 月 6 号与你相遇!

College personnel management system based on jsp+servlet

Bulletgraph (bullet diagram, bullet diagram)

Redis持久化RDB/AOF

Offer set (1)

Understand in depth why not use system.out.println()

Baidu PaddlePaddle easydl x wesken: see how to install the "eye of AI" in bearing quality inspection
随机推荐
Redis持久化RDB/AOF
Nailing third-party service provider application ISV application development and listing tutorial
如何做好测试用例设计
offer-集合(1)
钉钉第三方服务商应用ISV应用开发及上架教程
测试组如何进行QA规范
深入理解为什么不要使用System.out.println()
Leetcode 0139. word splitting
数据库索引的原理,为什么要用 B+树,为什么不用二叉树?
第一个ABAP ALV报表程序构建流程
Download and configuration of irrklang audio library
LeetCode_ 1005_ Maximized array sum after K negations
PS_1_认识主界面_新建文档(分辨率)_打开保存(序列动画)
Real passwords do not match during synchronization
Linear regression -- Taking an arithmetic sequence as an example
百度飞桨EasyDL X 韦士肯:看轴承质检如何装上“AI之眼”
Data warehouse: fact table of detailed dimensional modeling
SSM practice day 5
Become a test / development programmer, Xiao Zhang: reality is coming
The third day of SSM practice_ Paging assistant_ Security framework