<s> from flask import Flask , render_template , request , jsonify <EOL> from config import BUCKET_NAME , CALLBACK_URL , Q_DOMAIN , NEED_EXPIRE <EOL> from q import qiniu <EOL> app = Flask ( __name__ ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> policy = qiniu . rs . PutPolicy ( BUCKET_NAME ) <EOL> policy . callbackBody = '<STR_LIT>' <EOL> policy . callbackUrl = CALLBACK_URL <EOL> up_token = policy . token ( ) <EOL> return render_template ( '<STR_LIT>' , up_token = up_token ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> def upload_callback ( ) : <EOL> key = request . form [ '<STR_LIT:key>' ] <EOL> download_url = qiniu . rs . make_base_url ( Q_DOMAIN , key ) <EOL> if NEED_EXPIRE : <EOL> from cleaner import add_to_expire_queue <EOL> add_to_expire_queue ( key ) <EOL> return jsonify ( download_url = download_url ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app . run ( debug = True ) </s>
