@@ -56,7 +56,6 @@ public function __construct(
56
56
$ this ->setApiBaseUrl ($ apiBaseUrl ?? 'https://sharpapi.com/api/v1 ' );
57
57
$ this ->setUserAgent ($ userAgent ?? 'SharpAPIPHPAgent/1.2.0 ' );
58
58
$ this ->client = new Client ([
59
- 'base_uri ' => $ this ->getApiBaseUrl (),
60
59
'headers ' => $ this ->getHeaders ()
61
60
]);
62
61
}
@@ -191,24 +190,36 @@ protected function makeRequest(
191
190
array $ data = [],
192
191
?string $ filePath = null
193
192
): ResponseInterface {
194
- $ client = new Client ();
195
193
$ options = [
196
194
'headers ' => $ this ->getHeaders (),
197
195
];
196
+
198
197
if ($ method === 'POST ' ) {
199
198
if (is_string ($ filePath ) && strlen ($ filePath )) {
200
- $ options ['multipart ' ][] =
201
- [
202
- 'name ' => 'file ' ,
203
- 'contents ' => file_get_contents ($ filePath ),
204
- 'filename ' => basename ($ filePath ),
199
+ $ multipart = [];
200
+
201
+ // Attach file
202
+ $ multipart [] = [
203
+ 'name ' => 'file ' ,
204
+ 'contents ' => file_get_contents ($ filePath ),
205
+ 'filename ' => basename ($ filePath ),
206
+ ];
207
+
208
+ // Add each key-value pair from $data as a form-data field
209
+ foreach ($ data as $ key => $ value ) {
210
+ $ multipart [] = [
211
+ 'name ' => $ key ,
212
+ 'contents ' => is_array ($ value ) ? json_encode ($ value ) : $ value ,
205
213
];
214
+ }
215
+
216
+ $ options ['multipart ' ] = $ multipart ;
206
217
} else {
207
218
$ options ['json ' ] = $ data ;
208
219
}
209
220
}
210
221
211
- return $ client ->request ($ method , $ this ->getApiBaseUrl (). $ url , $ options );
222
+ return $ this -> client ->request ($ method , $ this ->getApiBaseUrl () . $ url , $ options );
212
223
}
213
224
214
225
/**
0 commit comments