11from typing import Any
22
33import httpx
4- import requests
54from httpx import HTTPError
6- from requests import HTTPError as RequestsHTTPError
7- from requests_toolbelt import MultipartEncoder
85
96
107class StorageFileAPI :
@@ -17,8 +14,8 @@ class StorageFileAPI:
1714 },
1815 }
1916 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" ,
2219 "x-upsert" : "false" ,
2320 }
2421
@@ -191,18 +188,15 @@ def upload(self, path: str, file: Any, file_options: dict = None):
191188 headers = dict (self .headers , ** self .DEFAULT_FILE_OPTIONS )
192189 headers .update (file_options )
193190 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" ))}
198192 _path = self ._get_final_path (path )
199193 try :
200- resp = requests .post (
194+ resp = httpx .post (
201195 f"{ self .url } /object/{ _path } " ,
202- data = files ,
196+ files = files ,
203197 headers = headers ,
204198 )
205- except RequestsHTTPError as http_err :
199+ except HTTPError as http_err :
206200 print (f"HTTP error occurred: { http_err } " ) # Python 3.6
207201 except Exception as err :
208202 raise err # Python 3.6
0 commit comments