当前位置:网站首页>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
}
})
边栏推荐
- 110 MySQL interview questions and answers (continuously updated)
- 【MySQL 8】Generated Invisible Primary Keys(GIPK)
- Brief introduction to compressed sensing
- Advanced area of attack and defense world web masters ics-06
- CDN mode uses vant components, and components cannot be called after they are introduced
- PTA (daily question) 7-72 calculate the cumulative sum
- Shell编程规范与变量
- PTA (daily question) 7-77 encryption
- Soft test --- database (4) SQL statement
- Statistical analysis of time series
猜你喜欢

Newscenter, advanced area of attack and defense world web masters

Web系统常见安全漏洞介绍及解决方案-sql注入

vscode下链接远程服务器安装插件失败、速度慢等解决方法

Api 接口优化有哪些技巧?

Linux下安装Mysql5.7,超详细完整教程,以及云mysql连接

【开发教程10】疯壳·开源蓝牙心率防水运动手环-蓝牙 BLE 收发

Dynamic programming problem (3)

What are the skills of API interface optimization?

动态规划问题(八)

IDEA 连接 数据库
随机推荐
Linux下安装Mysql5.7,超详细完整教程,以及云mysql连接
Mock.js essay
Camera Hal OEM模块 ---- cmr_preview.c
Shell编程规范与变量
Cause analysis of 12 MySQL slow queries
SAP vl02n delivery note posting function WS_ DELIVERY_ UPDATE
手把手教你安装Latex(保姆级教程)
Do like and in indexes in MySQL go
“吃货联盟定餐系统”
动态规划问题(八)
Software designer afternoon question
MySQL stored procedure
Longest ascending subsequence
动态规划问题(六)
Kali installs burpsuite professional
Summary: the difference between pod and container
Dynamic programming (V)
2022dasctfjuly empowerment competition (reappearance)
Teach you how to install latex (nanny level tutorial)
How to learn R language