Seven cow cloud storage instance is used in Python Web framework Flask

  • 2020-04-02 14:33:01
  • OfStack

For small sites, the free quota of using qiniu cloud storage is enough to provide a stable and fast storage service for the site

Seven NiuYun storage already (link: https://github.com/qiniu/python-sdk), to simple packaging, it can directly use in Flask, see project code on the lot (link: https://github.com/csuzhangxc/Flask-QiniuStorage).

Using sample code:


from flask import Flask
from flask_qiniustorage import Qiniu
 
QINIU_ACCESS_KEY = ' Seven cattle Access Key'
QINIU_SECRET_KEY = ' Seven cattle Secret Key'
QINIU_BUCKET_NAME = ' Seven newtons space name '
QINIU_BUCKET_DOMAIN = ' Seven cow 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 cow
@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)
 
# Gets the corresponding exposure by file name URL
@app.route('/url')
def url():
    filename = 'filename'
    return qiniu_store.url(filename)


Related articles: