Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions lib/Service/DropboxAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function downloadFile(string $accessToken, string $refreshToken, string $
'User-Agent' => 'Nextcloud Dropbox integration',
'Dropbox-API-Arg' => json_encode(['path' => $fileId]),
],
'stream' => true,
'sink' => $resource,
];

$response = $this->client->post($url, $options);
Expand All @@ -168,25 +168,13 @@ public function downloadFile(string $accessToken, string $refreshToken, string $
if ($respCode >= 400) {
return ['error' => $this->l10n->t('Bad credentials')];
}

$body = $response->getBody();
if (is_resource($body)) {
while (!feof($body)) {
// write ~5 MB chunks
$chunk = fread($body, 5000000);
fwrite($resource, $chunk);
}
} else {
fwrite($resource, $body);
}

return ['success' => true];
} catch (ServerException|ClientException $e) {
$response = $e->getResponse();
if ($response->getStatusCode() === 401) {
if ($try > 3) {
// impossible to refresh the token
$this->logger->info('Received the following response upon trying to download a file: ' . $response->getBody()->getContents());
$this->logger->info('Could not access file due to failed authentication.');
return ['error' => $this->l10n->t('Could not access file due to failed authentication.')];
}
$this->logger->info('Trying to REFRESH the access token', ['app' => $this->appName]);
Expand Down
4 changes: 3 additions & 1 deletion lib/Service/DropboxStorageAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ private function getFile(string $accessToken, string $refreshToken, string $clie
}
return null;
}
fclose($resource);
if (is_resource($resource)) {
fclose($resource);
}
if (isset($fileItem['server_modified'])) {
$d = new DateTime($fileItem['server_modified']);
$ts = $d->getTimestamp();
Expand Down
Loading