Skip to content

Commit efae1d4

Browse files
authored
Merge pull request #11 from fsalomon/master
Minimal multipart post support
2 parents 44922db + 9318ff4 commit efae1d4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Client/RequestBuilder.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ public function create(): RequestInterface
118118

119119
if ($this->data['method'] !== self::HTTP_GET) {
120120
curl_setopt($this->curl, CURLOPT_POST, true);
121-
curl_setopt($this->curl, CURLOPT_POSTFIELDS, json_encode($this->data['fields']));
121+
if ($this->isMultipart()) {
122+
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $this->data['fields']);
123+
} else {
124+
curl_setopt($this->curl, CURLOPT_POSTFIELDS, json_encode($this->data['fields']));
125+
}
122126
}
123127

124128
$request = new Request($this->curl);
@@ -137,7 +141,7 @@ private function buildHeaders(): array
137141
{
138142
$headers = [
139143
ZohoOAuthConstants::AUTHORIZATION . ':' . ZohoOAuthConstants::OAUTH_HEADER_PREFIX . $this->client->getAccessToken(),
140-
'Content-Type:application/json'
144+
'Content-Type: ' . ($this->isMultipart() ? 'multipart/form-data' : 'application/json'),
141145
];
142146

143147
if ($this->client->getOrgId()) {
@@ -147,6 +151,10 @@ private function buildHeaders(): array
147151
return $headers;
148152
}
149153

154+
private function isMultipart() {
155+
return isset($this->data['fields']['file']) && $this->data['fields']['file'] instanceof \CURLFile;
156+
}
157+
150158
private function buildUrl(): string
151159
{
152160
$url = sprintf(

0 commit comments

Comments
 (0)