Exemple #1
0
def upload():
    if 'fileVal' not in request.files:
        response = make_response("upload failed")
        response.status_code = 501
        return response
    file = request.files['fileVal']
    domain = current_app.config.get("QINIU_BUCKET_DOMAIN")
    result = upload_file(file, "app/static/upload", domain, Qiniu(current_app))
    return jsonify(result)
Exemple #2
0
    def _save_file(self, data, filename):
        path = self._get_path(filename)
        if not op.exists(op.dirname(path)):
            os.makedirs(os.path.dirname(path), self.permission | 0o111)

        data.seek(0)
        data.save(path)
        qiniu_store = Qiniu(current_app)
        with open(path, 'rb') as fp:
            ret, info = qiniu_store.save(fp, filename)
            if 200 != info.status_code:
                raise Exception("upload to qiniu failed", ret)
            # shutil.rmtree(os.path.dirname(path))
            return filename
Exemple #3
0
from flask import Flask
from flask_bootstrap import Bootstrap
from flask_qiniustorage import Qiniu
from flask_admin import Admin
import redis
from flask_cache import Cache

app = Flask(__name__, instance_relative_config=True)
app.config.from_object('config')
app.config.from_pyfile('localConfig.py')

bootstrap = Bootstrap(app)
qiniu_store = Qiniu(app)
admin = Admin(app)
QINIU_DOMAIN = app.config.get('QINIU_BUCKET_DOMAIN', '')
CATEGORY = app.config.get('CATEGORY')
UPLOAD_URL = app.config.get('UPLOAD_URL')
API_PREFIX = app.config.get('API_PREFIX')
SECRET_KEY = app.config.get("SECRET_KEY")

cache = Cache(app,
              config={
                  'CACHE_TYPE': 'simple',
                  "CACHE_REDIS_HOST": app.config.get("REDIS_HOST"),
                  "CACHE_REDIS_PORT": app.config.get("REDIS_PORT")
              })
Exemple #4
0
 def setUp(self):
     self.app = Flask(__name__)
     self.app.config.from_object(__name__)
     self.qiniu = Qiniu(self.app)
Exemple #5
0
from config import config
from flask import Flask
from flask_bootstrap import Bootstrap
from flask_qiniustorage import Qiniu
from flask_admin import Admin
from flask_cache import Cache
import flask_restless
from flask_sqlalchemy import SQLAlchemy
from flask_jwt import JWT

bootstrap = Bootstrap()
qiniu = Qiniu()
admin = Admin()
cache = Cache()
db = SQLAlchemy()
apiManager = flask_restless.APIManager()
jwt = JWT()


def app_creat(config_name):
    from moduleLogin import authenticate, identity
    from API import creatAPI
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_object(config[config_name])
    app.config.from_pyfile("localConfig.py")
    bootstrap.init_app(app)
    qiniu.init_app(app)
    admin.init_app(app)
    cache.init_app(app)
    db.__init__(app)
    apiManager.__init__(app, flask_sqlalchemy_db=db)
Exemple #6
0
from flask_sqlalchemy import SQLAlchemy
from flask_mail import Mail
from flask_qiniustorage import Qiniu
from flask_wtf.csrf import CSRFProtect

db = SQLAlchemy()

mail = Mail()

qiniu_store = Qiniu()

csrf = CSRFProtect()