@@ -56,7 +56,6 @@ public function __construct(
5656 $ this ->setApiBaseUrl ($ apiBaseUrl ?? 'https://sharpapi.com/api/v1 ' );
5757 $ this ->setUserAgent ($ userAgent ?? 'SharpAPIPHPAgent/1.2.0 ' );
5858 $ this ->client = new Client ([
59- 'base_uri ' => $ this ->getApiBaseUrl (),
6059 'headers ' => $ this ->getHeaders ()
6160 ]);
6261 }
@@ -191,24 +190,36 @@ protected function makeRequest(
191190 array $ data = [],
192191 ?string $ filePath = null
193192 ): ResponseInterface {
194- $ client = new Client ();
195193 $ options = [
196194 'headers ' => $ this ->getHeaders (),
197195 ];
196+
198197 if ($ method === 'POST ' ) {
199198 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 ,
205213 ];
214+ }
215+
216+ $ options ['multipart ' ] = $ multipart ;
206217 } else {
207218 $ options ['json ' ] = $ data ;
208219 }
209220 }
210221
211- return $ client ->request ($ method , $ this ->getApiBaseUrl (). $ url , $ options );
222+ return $ this -> client ->request ($ method , $ this ->getApiBaseUrl () . $ url , $ options );
212223 }
213224
214225 /**
0 commit comments