当前位置:网站首页>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
}
})
边栏推荐
- Soft test --- database (4) SQL statement
- Attack and defense world web master advanced area php2
- Attack and defense world web master advanced area PHP_ rce
- The download file of native JS implementation can be used anywhere
- PHP语言基础知识(超详细)
- Camera Hal OEM模块 ---- cmr_preview.c
- Attack and defense world web master advanced area web_ php_ unserialize
- PTA (daily question) 7-74 yesterday
- @PostConstruct注解详解
- Api 接口优化有哪些技巧?
猜你喜欢
递归/回溯刷题(下)
2022DASCTF7月赋能赛(复现)
2022dasctfjuly empowerment competition (reappearance)
Advanced area of attack and defense world web masters warmup
Software designer - intermediate, exam summary
MySQL stored procedure
Advanced area of attack and defense world web masters -baby Web
Where is sandbox's confidence in rejecting meta's acquisition of meta universe leader sand?
IMG tags prohibit dragging pictures
Oracle实例无法启动的问题如何解决
随机推荐
手把手教你安装Latex(保姆级教程)
乱打日志的男孩运气怎么样我不知道,加班肯定很多!
Dynamic programming problem (VIII)
2022DASCTF7月赋能赛(复现)
CV semantic segmentation model sketch (2)
Geth installation
动态规划问题(八)
MQ 消息丢失、重复、积压问题,如何解决?
Advanced area of attack and defense world web masters training www robots
分布式限流 redission RRateLimiter 的使用及原理
聊聊异步编程的 7 种实现方式
时间序列统计分析
PTA (one question per day) 7-76 ratio
Basic knowledge of PHP language (super detailed)
MySQL 分库分表及其平滑扩容方案
How to solve the problem that the Oracle instance cannot be started
Linux下安装Mysql5.7,超详细完整教程,以及云mysql连接
Dynamic programming problem (1)
Attack and defense world web master advanced area php2
CDN mode uses vant components, and components cannot be called after they are introduced