Skip to content

Commit 01c8830

Browse files
committed
fix(downloadFile): write directly to file using Guzzle's "sink" option
Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
1 parent fd54d2e commit 01c8830

1 file changed

Lines changed: 1 addition & 13 deletions

File tree

lib/Service/DropboxAPIService.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function downloadFile(string $accessToken, string $refreshToken, string $
159159
'User-Agent' => 'Nextcloud Dropbox integration',
160160
'Dropbox-API-Arg' => json_encode(['path' => $fileId]),
161161
],
162-
'stream' => true,
162+
'sink' => $resource,
163163
];
164164

165165
$response = $this->client->post($url, $options);
@@ -168,18 +168,6 @@ public function downloadFile(string $accessToken, string $refreshToken, string $
168168
if ($respCode >= 400) {
169169
return ['error' => $this->l10n->t('Bad credentials')];
170170
}
171-
172-
$body = $response->getBody();
173-
if (is_resource($body)) {
174-
while (!feof($body)) {
175-
// write ~5 MB chunks
176-
$chunk = fread($body, 5000000);
177-
fwrite($resource, $chunk);
178-
}
179-
} else {
180-
fwrite($resource, $body);
181-
}
182-
183171
return ['success' => true];
184172
} catch (ServerException|ClientException $e) {
185173
$response = $e->getResponse();

0 commit comments

Comments
 (0)