For projects deployed on the Sina application engine SAE, using the Sina SAE cloud storage is a good storage solution.
Sina SAE Cloud storage can only be used in SAE environment, after simple encapsulation, can be used directly in Flask, project code see GitHub on Flask-saestorage.
Using sample code:
Copy Code code 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 files to SAE Storage
@app. Route ('/save ')
def save ():
data = ' Data to save '
filename = ' filename '
RET = sae_storage.save (data, filename)
Return STR (ret)
# Delete the files in SAE storage
@app. Route ('/delete ')
def delete ():
filename = ' filename '
ret = sae_storage.delete (filename)
Return STR (ret)
# get the corresponding public URL based on the filename
@app. Route ('/url ')
def URL ():
filename = ' filename '
return Sae_storage.url (filename)