@@ -14,6 +14,18 @@ def post(self, path, payload, timeout = None):
1414 r = requests .post (self .url (path ), data = payload , headers = self .headers (), timeout = timeout )
1515 return self .handle_response (r )
1616
17+ def upload (self , io , filename ):
18+ url = convertapi .base_uri + 'upload'
19+ encoded_filename = requests .utils .quote (filename )
20+
21+ headers = self .headers ()
22+ headers .update ({
23+ 'Content-Disposition' : "attachment; filename*=UTF-8''" + encoded_filename ,
24+ })
25+
26+ r = requests .post (url , data = io , headers = headers , timeout = convertapi .upload_timeout )
27+ return self .handle_response (r )
28+
1729 def download (self , url , path ):
1830 r = requests .get (url , stream = True , timeout = convertapi .download_timeout )
1931
@@ -25,14 +37,12 @@ def download(self, url, path):
2537 return path
2638
2739 def handle_response (self , r ):
28- json = r .json ()
29-
30- if r .status_code >= 400 :
31- raise ConvertApiError (json ['Message' ])
32-
3340 r .raise_for_status ()
3441
35- return json
42+ # if r.status_code >= 400:
43+ # raise ConvertApiError(json['Message'])
44+
45+ return r .json ()
3646
3747 def url (self , path ):
3848 return "%s%s?Secret=%s" % (convertapi .base_uri , path , convertapi .api_secret )
0 commit comments