Skip to content

Commit 924d72a

Browse files
committed
fix: revert multipart
1 parent 221040c commit 924d72a

20 files changed

+865
-428
lines changed

appwrite/client.py

+29-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import io
12
import json
3+
import os
24
import requests
3-
from .payload import Payload
4-
from .multipart import MultipartParser
5+
from .input_file import InputFile
56
from .exception import AppwriteException
67
from .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(

appwrite/enums/runtime.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Runtime(Enum):
77
NODE_19_0 = "node-19.0"
88
NODE_20_0 = "node-20.0"
99
NODE_21_0 = "node-21.0"
10+
NODE_22 = "node-22"
1011
PHP_8_0 = "php-8.0"
1112
PHP_8_1 = "php-8.1"
1213
PHP_8_2 = "php-8.2"
@@ -25,28 +26,36 @@ class Runtime(Enum):
2526
DENO_1_24 = "deno-1.24"
2627
DENO_1_35 = "deno-1.35"
2728
DENO_1_40 = "deno-1.40"
29+
DENO_1_46 = "deno-1.46"
30+
DENO_2_0 = "deno-2.0"
2831
DART_2_15 = "dart-2.15"
2932
DART_2_16 = "dart-2.16"
3033
DART_2_17 = "dart-2.17"
3134
DART_2_18 = "dart-2.18"
3235
DART_3_0 = "dart-3.0"
3336
DART_3_1 = "dart-3.1"
3437
DART_3_3 = "dart-3.3"
35-
DOTNET_3_1 = "dotnet-3.1"
38+
DART_3_5 = "dart-3.5"
3639
DOTNET_6_0 = "dotnet-6.0"
3740
DOTNET_7_0 = "dotnet-7.0"
41+
DOTNET_8_0 = "dotnet-8.0"
3842
JAVA_8_0 = "java-8.0"
3943
JAVA_11_0 = "java-11.0"
4044
JAVA_17_0 = "java-17.0"
4145
JAVA_18_0 = "java-18.0"
4246
JAVA_21_0 = "java-21.0"
47+
JAVA_22 = "java-22"
4348
SWIFT_5_5 = "swift-5.5"
4449
SWIFT_5_8 = "swift-5.8"
4550
SWIFT_5_9 = "swift-5.9"
51+
SWIFT_5_10 = "swift-5.10"
4652
KOTLIN_1_6 = "kotlin-1.6"
4753
KOTLIN_1_8 = "kotlin-1.8"
4854
KOTLIN_1_9 = "kotlin-1.9"
55+
KOTLIN_2_0 = "kotlin-2.0"
4956
CPP_17 = "cpp-17"
5057
CPP_20 = "cpp-20"
5158
BUN_1_0 = "bun-1.0"
59+
BUN_1_1 = "bun-1.1"
5260
GO_1_23 = "go-1.23"
61+
STATIC_1 = "static-1"

appwrite/input_file.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os
2+
import mimetypes
3+
4+
class InputFile:
5+
@classmethod
6+
def from_path(cls, path):
7+
instance = cls()
8+
instance.path = path
9+
instance.filename = os.path.basename(path)
10+
instance.mime_type = mimetypes.guess_type(path)
11+
instance.source_type = 'path'
12+
return instance
13+
14+
@classmethod
15+
def from_bytes(cls, bytes, filename, mime_type = None):
16+
instance = cls()
17+
instance.data = bytes
18+
instance.filename = filename
19+
instance.mime_type = mime_type
20+
instance.source_type = 'bytes'
21+
return instance

appwrite/multipart.py

-49
This file was deleted.

appwrite/payload.py

-72
This file was deleted.

0 commit comments

Comments
 (0)