Use the Sina SAE cloud storage instance and flasksae In the Python Web framework Flask
For projects deployed on Sina application engine SAE, using Sina SAE cloud storage is a good storage solution.
Sina SAE cloud storage can only be used normally in the SAE environment. After simple encapsulation, it can be used directly in Flask. For project code, see Flask-SaeStorage on GitHub.
Sample Code:
Copy codeThe Code is as follows:
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)
# Or
# Sae_storage = SaeStorage ()
# Sae_storage.init_app (app)
# Save the file to SAE Storage
@ App. route ('/save ')
Def save ():
Data = 'data to save'
Filename = 'filename'
Ret = sae_storage.save (data, filename)
Return str (ret)
# Deleting files in SAE Storage
@ App. route ('/delete ')
Def delete ():
Filename = 'filename'
Ret = sae_storage.delete (filename)
Return str (ret)
# Obtain the public URL Based on the file name
@ App. route ('/url ')
Def url ():
Filename = 'filename'
Return sae_storage.url (filename)