1
1
from typing import Any
2
2
3
3
import httpx
4
- import requests
5
4
from httpx import HTTPError
6
- from requests import HTTPError as RequestsHTTPError
7
- from requests_toolbelt import MultipartEncoder
8
5
9
6
10
7
class StorageFileAPI :
@@ -17,8 +14,8 @@ class StorageFileAPI:
17
14
},
18
15
}
19
16
DEFAULT_FILE_OPTIONS = {
20
- "cacheControl " : "3600" ,
21
- "contentType " : "text/plain;charset=UTF-8" ,
17
+ "cache-control " : "3600" ,
18
+ "content-type " : "text/plain;charset=UTF-8" ,
22
19
"x-upsert" : "false" ,
23
20
}
24
21
@@ -191,18 +188,15 @@ def upload(self, path: str, file: Any, file_options: dict = None):
191
188
headers = dict (self .headers , ** self .DEFAULT_FILE_OPTIONS )
192
189
headers .update (file_options )
193
190
filename = path .rsplit ("/" , maxsplit = 1 )[- 1 ]
194
- files = MultipartEncoder (
195
- fields = {"file" : (filename , open (file , "rb" ), headers ["contentType" ])}
196
- )
197
- headers ["Content-Type" ] = files .content_type
191
+ files = {"file" : (filename , open (file , "rb" ), headers .pop ("content-type" ))}
198
192
_path = self ._get_final_path (path )
199
193
try :
200
- resp = requests .post (
194
+ resp = httpx .post (
201
195
f"{ self .url } /object/{ _path } " ,
202
- data = files ,
196
+ files = files ,
203
197
headers = headers ,
204
198
)
205
- except RequestsHTTPError as http_err :
199
+ except HTTPError as http_err :
206
200
print (f"HTTP error occurred: { http_err } " ) # Python 3.6
207
201
except Exception as err :
208
202
raise err # Python 3.6
0 commit comments