百度云存储BCS(Baidu Cloud Storage)Flask扩展,BCS(Baidu Cloud Storage) for Flask
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
pybcs
.gitignore
LICENSE
MANIFEST.in
README.md
README.rst_for_build
flask_bcs.py
setup.cfg
setup.py
tests.py

README.md

Flask-BCS

百度云存储BCS(Baidu Cloud Storage)Flask扩展,BCS(Baidu Cloud Storage) for Flask

安装

pip install Flask-BCS

本扩展使用了BCS Python SDK,pip安装时会自动包含该SDK。详细说明请参考BCS 文档

配置

配置项 说明
BCS_HOST BCS HOST
BCS_ACCESS_KEY BCS Access Key
BCS_SECRET_KEY BCS Secret Key
BCS_BUCKET_NAME BCS 空间名称

使用

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)
# 或者
# bcs = BCS()
# bcs.init_app(app)

# 保存文件到BCS
@app.route('/save')
def save():
    data = 'data to save'
    filename = 'filename'
    allow_referers = ['http://*.duapp.com/*', 'http://zhangxc.com/*']
    # 不设置allow_referers为完全public
    ret = bcs.save(data, filename, allow_referers)
    return str(ret)

# 删除BCS中的文件
@app.route('/delete')
def delete():
    filename = 'filename'
    ret = bcs.delete(filename)
    return str(ret)

# 根据文件名获取对应的公开URL
@app.route('/url')
def url():
    filename = 'filename'
    return bcs.url(filename)

参考tests.py

返回值

savedelete返回值为BCS Python SDK中对应API的返回值。

测试

$ python tests.py

许可

The MIT License (MIT). 详情见 License文件