For projects deployed on the Baidu application engine Bae, using the Baidu Cloud storage BCS (Storage) is a good storage solution.
Baidu Cloud storage already has Python SDK, it is simple encapsulation, it can be used directly in Flask, project code see FLASK-BCS on GitHub.
Use the sample code:
The code is 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)
# gets the corresponding public URL according to the file name
@app. Route ('/url ')
def URL ():
filename = ' filename '
return Bcs.url (filename)