-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.py
27 lines (19 loc) · 864 Bytes
/
upload.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
import requests
import json
import os
from requests_toolbelt import MultipartEncoder
import parameters
from datetime import datetime
current_date = datetime.now()
print(current_date.isoformat())
def upload_recording(filename, DOA):
# Upload the recordings to the Cacophony server
props = {"type": "audio", "duration": 60, "additionalMetaData": DOA, "recordingDateTime": current_date.isoformat()}
json_props = json.dumps(props)
with open(filename, "rb") as content:
multipart_data = MultipartEncoder(
fields = {"data": json_props, "file": (os.path.basename(filename), content)}
)
headers = {"Content-type": multipart_data.content_type, "Authorization": parameters.user_token}
response = requests.request("POST", parameters.upload, headers=headers, data=multipart_data)
print(response.text)