对于部署在百度应用引擎BAE上的项目,使用百度云存储BCS(Baidu Cloud Storage)是不错的存储方案。
百度云存储已有Python SDK,对它进行简单封装后,就可以直接在Flask中使用了,项目代码见GitHub上Flask-BCS。
使用示例代码:
复制代码 代码如下:
from flask import Flask
from flask_bcs import BCS
BCS_HOST = 'BCS HOST'
BCS_ACCESS_KEY = 'BCS Access Key'
BCS_SECRET_KEY = 'BCS Secret Key'
BCS_BUCKET_NAME = 'BCS Bucket Name'
app = Flask(name)
app.config.from_object(name)
bcs = BCS(app)
@app.route('/save')
def save():
data = 'data to save'
filename = 'filename'
allow_referers = ['http://.duapp.com/', 'http://zhangxc.com/*']
ret = bcs.save(data, filename, allow_referers)
return str(ret)
@app.route('/delete')
def delete():
filename = 'filename'
ret = bcs.delete(filename)
return str(ret)
@app.route('/url')
def url():
filename = 'filename'
return bcs.url(filename)
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8