Skip to content

Commit

Permalink
Add support for multipart request shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Jan 19, 2024
1 parent d8ca65e commit d5e9c1e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/base/ProviderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function getApiRequest(string $method = 'GET', string $uri = '', Token $t
$token = $this->refreshToken($token);
$accessToken = $token->getToken();

// Normalise passing in `form_params` or `json`, like Guzzle normally would
// Normalise passing in `form_params`, `json` or `multipart`, like Guzzle normally would
if ($json = ArrayHelper::remove($options, 'json')) {
$options['body'] = Json::encode($json);
$options['headers']['Content-Type'] = 'application/json';
Expand All @@ -117,6 +117,12 @@ public function getApiRequest(string $method = 'GET', string $uri = '', Token $t
$options['headers']['Content-Type'] = 'application/x-www-form-urlencoded';
}

if ($multipart = ArrayHelper::remove($options, 'multipart')) {
$options['body'] = $multipart;
$boundary = ArrayHelper::remove($options, 'boundary');
$options['headers']['Content-Type'] = 'multipart/form-data; boundary=' . $boundary;
}

// Perform the actual request
$request = $this->getAuthenticatedRequest($method, $url, $accessToken, $options);

Expand Down

0 comments on commit d5e9c1e

Please sign in to comment.