For projects deployed on the Baidu application engine Bae, using the Baidu Cloud storage BCS (Baidu Cloud Storage) is a good storage solution.
Baidu Cloud storage already has Python SDK, it carries on simple encapsulation, can be used directly in Flask, project code see GitHub on Flask-bcs.
Using sample code:
Copy Code code as follows:
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)
# or
# BCS = BCS ()
# Bcs.init_app (APP)
# Save files to BCS
@app. Route ('/save ')
def save ():
data = ' Data to save '
filename = ' filename '
Allow_referers = [' http://*.duapp.com/* ', ' http://zhangxc.com/* ']
# do not set Allow_referers to full public
RET = bcs.save (data, filename, allow_referers)
Return STR (ret)
# Delete Files in BCS
@app. Route ('/delete ')
def delete ():
filename = ' filename '
ret = bcs.delete (filename)
Return STR (ret)
# get the corresponding public URL based on the filename
@app. Route ('/url ')
def URL ():
filename = ' filename '
return Bcs.url (filename)