Skip to content

Commit 177b77b

Browse files
committed
Upload file route
1 parent 42f5ae8 commit 177b77b

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

api.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,18 @@ def resetDefaultPrograms():
145145
if filename.endswith(".json"):
146146
with open("data/defaults/programs/" + filename) as p:
147147
q = p.read()
148-
programs.insert(json.loads(q))
148+
programs.insert(json.loads(q))
149+
150+
def uploadFile():
151+
if 'file' not in request.files:
152+
return 'Bad request', 400
153+
file = request.files['file']
154+
if file.filename == '':
155+
return 'Bad request', 400
156+
if file:
157+
filename = file.filename
158+
folderPath = 'uploads'
159+
file.save(os.path.join(folderPath, filename))
160+
return 200
161+
else:
162+
return 400

v2.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,19 @@ paths:
7474
description: "ok"
7575
400:
7676
description: "Failed to save the activity"
77-
77+
/uploadFile:
78+
post:
79+
operationId: "api.uploadFile"
80+
parameters:
81+
- in: body
82+
name: data
83+
schema:
84+
type: object
85+
responses:
86+
200:
87+
description: "ok"
88+
400:
89+
description: "upload failed"
7890
/deleteActivity:
7991
post:
8092
operationId: "api.deleteActivity"
@@ -225,4 +237,4 @@ paths:
225237
description: Duration of the movement. -1 moves the bot until a /stop command is received.
226238
responses:
227239
200:
228-
description: Sent command to the bot GPIO.
240+
description: Sent command to the bot GPIO.

0 commit comments

Comments
 (0)