Using Sina SAE Cloud storage instance in Python Web framework Flask

Source: Internet
Author: User
For projects deployed on the 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, project code on GitHub flask-saestorage.

Use the sample code:
Copy the 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)

# Remove files from SAE storage
@app. Route ('/delete ')
def delete ():
filename = ' filename '
ret = sae_storage.delete (filename)
Return STR (ret)

# gets the corresponding public URL according to the file name
@app. Route ('/url ')
def URL ():
filename = ' filename '
return Sae_storage.url (filename)
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.