Python Web framework flask using seven Cow cloud storage instance _python

Source: Internet
Author: User

For small sites, a free quota of seven cattle cloud storage is sufficient to provide a stable, fast storage service for the site

Seven Neu Yun storage already has Python SDK, simple encapsulation to it, can be used directly in Flask, project code see GitHub on Flask-qiniustorage.

Using sample code:

Copy Code code as follows:

From flask import Flask
From Flask_qiniustorage import Qiniu

Qiniu_access_key = ' Seven Cattle ACCESS KEY '
Qiniu_secret_key = ' Seven ox SECRET KEY '
Qiniu_bucket_name = ' Seven Cattle space name '
Qiniu_bucket_domain = ' Seven cattle space corresponding domain name '

App = Flask (__name__)
App.config.from_object (__name__)
Qiniu_store = Qiniu (APP)
# or
# Qiniu_store = Qiniu ()
# Qiniu_store.init_app (APP)

# Save the file to seven cows
@app. Route ('/save ')
def save ():
data = ' Data to save '
filename = ' filename '
RET, info = qiniu_store.save (data, filename)
Return STR (ret)

# Delete files in seven-cow space
@app. Route ('/delete ')
def delete ():
filename = ' filename '
RET, info = qiniu_store.delete (filename)
Return STR (ret)

# get the corresponding public URL based on the filename
@app. Route ('/url ')
def URL ():
filename = ' filename '
return Qiniu_store.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.