forked from alexa-pi/AlexaPiDEPRECATED
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
executable file
·40 lines (36 loc) · 965 Bytes
/
server.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
35
36
37
38
39
40
#! /usr/bin/env python
from flask import Flask
from flask import request
import os
app = Flask(__name__)
x=0
'''This is a really crude server that i wrote up to transfer audio from my phone to the Pi. '''
@app.route('/upload', methods = ['POST'])
def upload_message():
global x
print(request.headers['Content-Type'])
if request.headers['Content-Type'].find('media/mpeg') != -1:
x+=1
f = open(str(x), 'wb')
f.write(request.data)
f.close()
return "Binary message written!"
else:
return "415 Unsupported Media Type ;)"
@app.route('/download',methods = ['GET'])
def download_message():
global x
if x >= 1:
request.data = open(str(x),'rb').read()
x-=1
request.status_code = 200
return request.data
else:
return "No Audio"
@app.route('/',methods = ['GET'])
def Hello():
return "Hello"
if __name__ == '__main__':
global x
x=0
app.run()