-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend-to-parse.py
34 lines (30 loc) · 1.03 KB
/
send-to-parse.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,httplib
appID = "kKW7oJS0nwEG4V6f3LvYooU5BQxFnH6eZ9aS31A3"
apiKey = "HEZHvUyEqV4VOV61YaEFbMywGKq7pJNlPhlQtWRt"
uploadFilename = "samples.txt"
connection = httplib.HTTPSConnection('api.parse.com', 443)
connection.connect()
connection.request('POST', '/1/files/' + uploadFilename, open(uploadFilename, 'rb').read(), {
"X-Parse-Application-Id": appID,
"X-Parse-REST-API-Key": apiKey,
"Content-Type": "text/plain"
})
result = json.loads(connection.getresponse().read())
filename = result["name"]
print filename + ' uploaded'
#Uploaded the file to Parse
#Now associate it with Event Object
connection.request('POST','/1/classes/EventObject', json.dumps({
"name": "Sample",
"data": {
"name": filename,
"__type": "File"
}
}), {
"X-Parse-Application-Id": appID,
"X-Parse-REST-API-Key": apiKey,
"Content-Type": "applicaton/json"
}
)
result = json.loads(connection.getresponse().read())
print filename + ' associated with object ' + result["objectId"]