The Python Web framework Flask uses Baidu cloud to store BCS instances and flaskbcs
For projects deployed on Baidu application engine BAE, using Baidu Cloud Storage BCS (Baidu Cloud Storage) is a good Storage solution.
Baidu cloud storage has Python SDK. After simple encapsulation, it can be used directly in Flask. For the project code, see Flask-BCS on GitHub.
Sample Code:
Copy codeThe 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 the file 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 completely public
Ret = bcs. save (data, filename, allow_referers)
Return str (ret)
# Deleting files in BCS
@ App. route ('/delete ')
Def delete ():
Filename = 'filename'
Ret = bcs. delete (filename)
Return str (ret)
# Obtain the public URL Based on the file name
@ App. route ('/url ')
Def url ():
Filename = 'filename'
Return bcs. url (filename)