1+ import io
12import json
3+ import os
24import requests
3- from .payload import Payload
4- from .multipart import MultipartParser
5+ from .input_file import InputFile
56from .exception import AppwriteException
67from .encoders .value_class_encoder import ValueClassEncoder
78
@@ -90,15 +91,11 @@ def call(self, method, path='', headers=None, params=None, response_type='json')
9091
9192 if headers ['content-type' ].startswith ('multipart/form-data' ):
9293 del headers ['content-type' ]
93- headers ['accept' ] = 'multipart/form-data'
9494 stringify = True
9595 for key in data .copy ():
96- if isinstance (data [key ], Payload ):
97- if data [key ].filename :
98- files [key ] = (data [key ].filename , data [key ].to_binary ())
99- del data [key ]
100- else :
101- data [key ] = data [key ].to_string ()
96+ if isinstance (data [key ], InputFile ):
97+ files [key ] = (data [key ].filename , data [key ].data )
98+ del data [key ]
10299 data = self .flatten (data , stringify = stringify )
103100
104101 response = None
@@ -129,9 +126,6 @@ def call(self, method, path='', headers=None, params=None, response_type='json')
129126 if content_type .startswith ('application/json' ):
130127 return response .json ()
131128
132- if content_type .startswith ('multipart/form-data' ):
133- return MultipartParser (response .content , content_type ).to_dict ()
134-
135129 return response ._content
136130 except Exception as e :
137131 if response != None :
@@ -152,10 +146,20 @@ def chunked_upload(
152146 on_progress = None ,
153147 upload_id = ''
154148 ):
155- payload = params [param_name ]
156- size = params [param_name ].size
149+ input_file = params [param_name ]
150+
151+ if input_file .source_type == 'path' :
152+ size = os .stat (input_file .path ).st_size
153+ input = open (input_file .path , 'rb' )
154+ elif input_file .source_type == 'bytes' :
155+ size = len (input_file .data )
156+ input = input_file .data
157+
158+ if size < self ._chunk_size :
159+ if input_file .source_type == 'path' :
160+ input_file .data = input .read ()
157161
158- if size < self . _chunk_size :
162+ params [ param_name ] = input_file
159163 return self .call (
160164 'post' ,
161165 path ,
@@ -178,10 +182,16 @@ def chunked_upload(
178182 input .seek (offset )
179183
180184 while offset < size :
181- params [param_name ] = Payload .from_binary (
182- payload .to_binary (offset , min (self ._chunk_size , size - offset )),
183- payload .filename
184- )
185+ if input_file .source_type == 'path' :
186+ input_file .data = input .read (self ._chunk_size ) or input .read (size - offset )
187+ elif input_file .source_type == 'bytes' :
188+ if offset + self ._chunk_size < size :
189+ end = offset + self ._chunk_size
190+ else :
191+ end = size - offset
192+ input_file .data = input [offset :end ]
193+
194+ params [param_name ] = input_file
185195 headers ["content-range" ] = f'bytes { offset } -{ min ((offset + self ._chunk_size ) - 1 , size - 1 )} /{ size } '
186196
187197 result = self .call (
0 commit comments