-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathserver.py
More file actions
38 lines (24 loc) · 728 Bytes
/
Copy pathserver.py
File metadata and controls
38 lines (24 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
# encoding: utf-8
from __future__ import absolute_import, division
import base64
from os.path import dirname, join, realpath
from flask import Flask, request
from flask.ext.cors import CORS
CURRENT_DIR = dirname(realpath(__file__))
IMAGES_DIR = join(CURRENT_DIR, 'images')
IMAGE_INDEX = 0
app = Flask(__name__)
CORS(app)
@app.route('/', methods=['GET', 'POST'])
def index():
global IMAGE_INDEX
png_data = request.form['imageData'].split(',')[-1]
decoded = base64.b64decode(png_data)
path = join(IMAGES_DIR, '%04d.png' % IMAGE_INDEX)
with open(path, 'w+') as f:
f.write(decoded)
IMAGE_INDEX += 1
return ''
if __name__ == '__main__':
app.run(debug=True)