对于小型站点,使用七牛云存储的免费配额已足够为站点提供稳定、快速的存储服务
七牛云存储已有Python SDK,对它进行简单封装后,就可以直接在Flask中使用了,项目代码见GitHub上Flask-QiniuStorage。
使用示例代码:
复制代码 代码如下:
from flask import Flask
from flask_qiniustorage import Qiniu
QINIU_ACCESS_KEY = '七牛 Access Key'
QINIU_SECRET_KEY = '七牛 Secret Key'
QINIU_BUCKET_NAME = '七牛空间名称'
QINIU_BUCKET_DOMAIN = '七牛空间对应域名'
app = Flask(name)
app.config.from_object(name)
qiniu_store = Qiniu(app)
@app.route('/save')
def save():
data = 'data to save'
filename = 'filename'
ret, info = qiniu_store.save(data, filename)
return str(ret)
@app.route('/delete')
def delete():
filename = 'filename'
ret, info = qiniu_store.delete(filename)
return str(ret)
@app.route('/url')
def url():
filename = 'filename'
return qiniu_store.url(filename)
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8