@@ -66,7 +66,7 @@ class Client:
66
66
stringify = True
67
67
for key in data.copy():
68
68
if isinstance(data[key], InputFile):
69
- files[key] = (data[key].name , data[key].file )
69
+ files[key] = (data[key].filename , data[key].data )
70
70
del data[key]
71
71
response = None
72
72
try:
@@ -108,21 +108,27 @@ class Client:
108
108
on_progress = None,
109
109
upload_id = ''
110
110
):
111
- file_path = str(params[param_name])
112
- file_name = os.path.basename(file_path)
113
- size = os.stat(file_path).st_size
111
+ input_file = params[param_name]
112
+
113
+ if input_file.source_type == 'path':
114
+ size = os.stat(input_file.path).st_size
115
+ input = open(input_file.path, 'rb')
116
+ elif input_file.source_type == 'bytes':
117
+ size = len(input_file.data)
118
+ input = input_file.data
114
119
115
120
if size < self._chunk_size:
116
- slice = open(file_path, 'rb').read()
117
- params[param_name] = InputFile(file_path, file_name, slice)
121
+ if input_file.source_type == 'path':
122
+ input_file.data = input.read()
123
+
124
+ params[param_name] = input_file
118
125
return self.call(
119
126
'post',
120
127
path,
121
128
headers,
122
129
params
123
130
)
124
131
125
- input = open(file_path, 'rb')
126
132
offset = 0
127
133
counter = 0
128
134
@@ -138,9 +144,16 @@ class Client:
138
144
input.seek(offset)
139
145
140
146
while offset < size:
141
- slice = input.read(self._chunk_size) or input.read(size - offset)
147
+ if input_file.source_type == 'path':
148
+ input_file.data = input.read(self._chunk_size) or input.read(size - offset)
149
+ elif input_file.source_type == 'bytes':
150
+ if offset + self._chunk_size < size:
151
+ end = offset + self._chunk_size
152
+ else:
153
+ end = size - offset
154
+ input_file.data = input[offset:end]
142
155
143
- params[param_name] = InputFile(file_path, file_name, slice)
156
+ params[param_name] = input_file
144
157
headers["content-range"] = f'bytes {offset}-{min((offset + self._chunk_size) - 1, size)}/{size}'
145
158
146
159
result = self.call(
0 commit comments