<filename>code/shtp2/server.py<gh_stars>1-10
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- Author: ClarkYAN -*-

from flask import Flask, request
from werkzeug.utils import secure_filename

import os
import pickle

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'data/'
app.config['ALLOWED_EXTENSIONS'] = set(['png', 'jpg', 'jpeg', 'gif', 'xls', 'xlsx', 'pdf', 'p'])


# For a given file, return whether it's an allowed type or not
def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS']


@app.route('/')
def connect():
    return 'connect to the cloud'


@app.route('/key', methods=['POST'])
def sendKey():
    # sender = request.data['data']
    #pubkey = pickle.load(open("keypair/pub_128.p", "rb"))
    files = open("keypair/pub_128.p", "rb")
    #pub = str(pubkey)
    #print pub
    return files


@app.route('/upload', methods=['POST'])
def upload():
    upload_file = request.files['dataset']
    if upload_file and allowed_file(upload_file.filename):
        filename = secure_filename(upload_file.filename)
        upload_file.save(os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], filename))
        return 'hello, ' + request.form.get('name', 'little apple') + '. success'
    else:
        return 'hello, ' + request.form.get('name', 'little apple') + '. failed'


if __name__ == '__main__':
    # app.run(host='0.0.0.0', port=5000, debug=True)
    app.run(host='127.0.0.1', port=5000, debug=True)

<filename>code/shtp2/server.py<gh_stars>1-10
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- Author: ClarkYAN -*-

from flask import Flask, request
from werkzeug.utils import secure_filename

import os
import pickle

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'data/'
app.config['ALLOWED_EXTENSIONS'] = set(['png', 'jpg', 'jpeg', 'gif', 'xls', 'xlsx', 'pdf', 'p'])


# For a given file, return whether it's an allowed type or not
def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS']


@app.route('/')
def connect():
    return 'connect to the cloud'


@app.route('/key', methods=['POST'])
def sendKey():
    # sender = request.data['data']
    #pubkey = pickle.load(open("keypair/pub_128.p", "rb"))
    files = open("keypair/pub_128.p", "rb")
    #pub = str(pubkey)
    #print pub
    return files


@app.route('/upload', methods=['POST'])
def upload():
    upload_file = request.files['dataset']
    if upload_file and allowed_file(upload_file.filename):
        filename = secure_filename(upload_file.filename)
        upload_file.save(os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], filename))
        return 'hello, ' + request.form.get('name', 'little apple') + '. success'
    else:
        return 'hello, ' + request.form.get('name', 'little apple') + '. failed'


if __name__ == '__main__':
    # app.run(host='0.0.0.0', port=5000, debug=True)
    app.run(host='127.0.0.1', port=5000, debug=True)

#!/usr/bin/env python # -*- coding: utf-8 -*- # -*- Author: ClarkYAN -*- # For a given file, return whether it's an allowed type or not # sender = request.data['data'] #pubkey = pickle.load(open("keypair/pub_128.p", "rb")) #pub = str(pubkey) #print pub # app.run(host='0.0.0.0', port=5000, debug=True)