-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload.py
More file actions
29 lines (24 loc) · 828 Bytes
/
upload.py
File metadata and controls
29 lines (24 loc) · 828 Bytes
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
import urllib3
import json
class Web3Storage:
def __init__(self):
self.http = urllib3.PoolManager()
def upload_single(self, file_name, file_path):
headers = {
"Content-Type": "multipart/form-data"
}
with open(file_path) as fp:
file_data = fp.read()
res = self.http.request(
"POST",
"http://127.0.0.1:9595/upload",
headers=headers,
fields={
"upload": (file_name, file_data)
}
)
return json.loads(res.data.decode('utf-8'), encoding='utf-8')
def get_status(self, cid):
res = self.http.request('GET',
'http://127.0.0.1:9595/cid/' + cid + '/status')
return json.loads(res.data.decode('utf-8'), encoding='utf-8')