flaskアップロードを実現
UPLOAD_FOLDER = 'ipa/'
ALLOWED_EXTENSIONS = set(['ipa'])
ALLOWED_TYPE = set(['online', 'offline', 'release'])
app = Flask(__name__)
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
def allowed_type(typename):
return typename in ALLOWED_TYPE
@app.route('/upload/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST' and request.form['type'] and allowed_type(request.form['type']):
file = request.files['file']
filename = request.form['rename'] if 'rename' in request.form else file.filename
print filename
if file and allowed_file(filename):
filename = secure_filename(filename)
file.save(os.path.join(UPLOAD_FOLDER, request.form['type'], filename))
return 'success
'
return 'failed
'
if __name__ == '__main__':
app.debug = True
app.run(host = '0.0.0.0', port = 8012)
対応するアップロードコマンド
curl -i -F "file=@${foo}/${bar}"-F "type=online"http://${ip}:${port}/upload/
curl -i -F "file=@${foo}/${bar}"-F "rename=${rename}"-F "type=online"http://${ip}:${port}/upload/