当前位置:网站首页>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
边栏推荐
- LeetCode_134_加油站
- OpenGL中的视差贴图的着色器代码
- Neural network learning (2) introduction 2
- ssm练习第四天_获取用户名_用户退出_用户crud_密码加密_角色_权限
- 百度飞桨EasyDL X 韦士肯:看轴承质检如何装上“AI之眼”
- 凝心聚力,心心向印!印度中资手机企业协会(CMA)正式运营!
- Ten year structure five year life-06 impulse to leave
- 成为测试/开发程序员,小张:现实就来了个下马威......
- BulletGraph(子弹图、项目符号图)
- Redis master-slave replication, read-write separation, sentinel mode
猜你喜欢

Meta Cambria手柄曝光,主动追踪+多触觉回馈方案

ECS MySQL prompt error

Efficiency increased by 98%! AI weapon behind operation and maintenance inspection of high altitude photovoltaic power station

面试OPPO,16道题甩过来,我人傻了

Download and configuration of irrklang audio library

Redis主从复制,读写分离,哨兵模式

Hello World

Still using xshell? Recommend this more modern terminal connection tool

Vector CANape - How to Send Receive CAN Message in CANape

Pyqt5 rapid development and practice 3.5 menu bar and toolbar
随机推荐
数据安全知识体系
Leetcode 0139. word splitting
神经网络学习(2)前言介绍二
PS_2_图层
[unity3d] rocker
Day 4 of SSM practice_ Get user name_ User exit_ User CRUD_ Password encryption_ Roles_ jurisdiction
你适合做自动化 测试吗?
[add conditional behavior in kotlin]
PS_1_认识主界面_新建文档(分辨率)_打开保存(序列动画)
OpenGL中的视差贴图的着色器代码
面试OPPO,16道题甩过来,我人傻了
J9 number theory: how to avoid the trap of stepping on thunder?
自动化测试工具-Playwright(快速上手)
PS_ 1_ Know the main interface_ New document (resolution)_ Open save (sequence animation)
The second day of SSM practice_ Project split moudle_ Basic addition, deletion, modification and query_ Batch delete_ One to one cascading query
文件上传下载测试点
Vector CANape - How to Send Receive CAN Message in CANape
骚操作:巧用MySQL主从复制延迟拯救误删数据
14. Gradient detection, random initialization, neural network Summary
Sword finger offer regular expression matching