Python Web framework flask using the Baidu Cloud store BCS instance _python

Source: Internet
Author: User

For projects deployed on the Baidu application engine Bae, using the Baidu Cloud storage BCS (Baidu Cloud Storage) is a good storage solution.

Baidu Cloud storage already has Python SDK, it carries on simple encapsulation, can be used directly in Flask, project code see GitHub on Flask-bcs.

Using sample code:

Copy Code code 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)

# get the corresponding public URL based on the filename
@app. Route ('/url ')
def URL ():
filename = ' filename '
return Bcs.url (filename)

Related Article

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.