-
Notifications
You must be signed in to change notification settings - Fork 0
/
flask_api.py
36 lines (22 loc) · 873 Bytes
/
flask_api.py
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
import json
from flask import Flask, jsonify, request
from werkzeug.utils import secure_filename
my_api = Flask(__name__)
@my_api.route('/')
def index():
return jsonify({'message': 'Index', 'data': None})
@my_api.route('/get_files', methods=['POST'])
def get_files():
file = request.files['file']
if file:
filename = secure_filename(file.filename)
file.save(filename)
with open(filename, 'r') as f:
data = json.load(f)
return jsonify({'success': True, 'message': 'DONE'})
#database_communication = do_stuff_with_data(data)
#if database_communication:
# return jsonify({'success': True, 'message': 'All worked fine'})
#else:
# return jsonify({'success': False, 'message': 'Something went wrong'})
return jsonify({'success': False, 'message': 'No file'})