Python Web框架Flask中使用新浪SAE云存储实例
对于部署在新浪应用引擎SAE上的项目,使用新浪SAE云存储是不错的存储方案。
新浪SAE云存储仅能在SAE环境中正常使用,对它进行简单封装后,可以直接在Flask中使用,项目代码见GitHub上Flask-SaeStorage。
使用示例代码:
代码如下:
from flask import Flask from flask_saestorage import SaeStorage SAE_ACCESS_KEY = 'SAE Access Key' SAE_SECRET_KEY = 'SAE Secret Key' SAE_APP_NAME = 'SAE App Name' SAE_BUCKET_NAME = 'SAE Bucket Name' app = Flask(__name__) app.config.from_object(__name__) sae_storage = SaeStorage(app) # 或者 # sae_storage = SaeStorage() # sae_storage.init_app(app) # 保存文件到SAE Storage @app.route('/save') def save(): data = 'data to save' filename = 'filename' ret = sae_storage.save(data, filename) return str(ret) # 删除SAE Storage中的文件 @app.route('/delete') def delete(): filename = 'filename' ret = sae_storage.delete(filename) return str(ret) # 根据文件名获取对应的公开URL @app.route('/url') def url(): filename = 'filename' return sae_storage.url(filename)
相关推荐
waitui00 2019-12-31
shangc 2016-11-17
zhichizhixiao0 2015-09-01
guowang0 2013-06-18
evilice 2011-11-29
cawebs 2016-11-17
heavstar 2019-06-21
tuxlcsdn 2019-06-21
haixianTV 2015-09-01
字节流动 2014-10-23
kongxingxing 2013-05-19
liutian0 2012-06-15
xlklmy 2016-02-15
好脑筋不如烂笔头 2016-02-14
微加幸福 2016-02-13
关山岂止万千重 2016-01-18
86407413 2016-01-05
anxiaomai0 2016-02-15
mantgh 2014-07-28