当前位置:网站首页>Flash and seven cattle cloud upload pictures
Flash and seven cattle cloud upload pictures
2022-07-29 00:36:00 【Wbig】
The use of seven cattle cloud
1. Know Qi niuyun
Qiniu cloud is quite an online storage space , You can access the stored pictures directly in the browser .
according to CDN Distribute to different network nodes , The browser fetches materials nearby , Get the picture , Render the page
Of course , Pictures stored in qiniu cloud also need to be stored locally .
2. Installation of seven cattle cloud
Input... At the terminal
pip install qiniu
Can be installed
3. Use qiniu cloud
Create a unique file for qiniu cloud , To use it , For what I got on the official website of qiniuyun ak,sk Etc , To perform encapsulation and encryption
from flask import current_app
from qiniu import Auth,put_file
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_NAME")
def upload(self,loacfilepath,newfilename):
token = self.q.upload_token(self.bucket_name,newfilename,3600)
print(token)
res = put_file(token,newfilename,loacfilepath,version="v2")
print(res)
if res[0]["key"] == newfilename:
return newfilename
else:
return False
if __name__ == '__main__':
from app import app
with app.app_context():
QiniuTool().upload("./../static/exo.jpg","static/img/exo.jpg")
Content of station closure , When calling, import directly according to your own file path
class SecretConfig():
QINIU_AK = "Ae95CnxjK5lryTj-Fb1Z_4sLWba_7XShIrvZBQoN"
QINIU_SK = "j5smR9D8hrf5DC2PnXD1XamwYWLyUJ1OdvaOPH9m"
QINIU_BUCKET_NAME = "p7uploadimg"
QINIU_URL = "http://rfluoehnd.hn-bkt.clouddn.com/"
4.flask Upload pictures with seven cattle cloud
To upload pictures, you need to upload them to the local first, and then upload them to qiniu cloud according to the local
class UploadView(Resource):
@login
def post(self):
img = request.files.get("img")
ext = img.filename.split(".")[-1]
now_time = datetime.strftime(datetime.now(),"%Y%m%d%H%M%S")
r = str(random.randint(100000,999999))
new_name = "%s%s.%s"%(now_time,r,ext)
save_path = "static/%s"%new_name
print(new_name)
img.save(save_path)
res = QiniuTool().upload(save_path,save_path)
if not res:
return jsonify({
"code": 400,
"msg": " File upload failed "
})
user_info = UserModel.query.get(g.uid)
user_info.img = save_path
db.session.commit()
return jsonify({
"code": 200,
"msg": " Upload successful ",
"data": {
"key":res
}
})
边栏推荐
- Simple use and understanding of laravel message queue
- Shell编程规范与变量
- ORACLE not available如何解决
- 16.偏差、方差、正则化、学习曲线对模型的影响
- Table custom style row class name in elemenui
- 1331. Array sequence number conversion: simple simulation question
- Attack and defense world web master advanced area PHP_ rce
- 总结:POD与容器的区别
- CV semantic segmentation model sketch (2)
- Software designer afternoon question
猜你喜欢

PTA (daily question) 7-77 encryption

Idea2021.2 installation and configuration (continuous update)

动态规划问题(七)

Recursion / backtracking (Part 2)

Still writing a lot of if to judge? A rule executor kills all if judgments in the project

Advanced area of attack and defense world web masters warmup

Dynamic programming (V)

ACM SIGIR 2022 | interpretation of selected papers of meituan technical team

15.模型评估和选择问题

PTA (daily question) 7-74 yesterday
随机推荐
Basic knowledge of PHP language (super detailed)
IMG tags prohibit dragging pictures
[small bug diary] Navicat failed to connect to MySQL | MySQL service disappeared | mysqld installation failed (this application cannot run on your computer)
There is a span tag. If you want to do click events on it, how can you expand the click area
15. Model evaluation and selection
Advanced area of attack and defense world web masters warmup
Advanced area of attack and defense world web masters -baby Web
MySQL的存储过程
17.机器学习系统的设计
【飞控开发基础教程8】疯壳·开源编队无人机-I2C(激光测距)
[develop low code platform] low code rendering
Summary: the difference between pod and container
Dynamic programming problem (VIII)
【MySQL 8】Generated Invisible Primary Keys(GIPK)
聊聊异步编程的 7 种实现方式
PTA (daily question) 7-72 calculate the cumulative sum
Kali installs burpsuite professional
@Detailed explanation of the use of transactional annotation
Shell编程规范与变量
Install mysql5.7 under Linux, super detailed complete tutorial, and cloud MySQL connection