summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/google.php
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-01-14 17:52:30 +0100
committerVincent Petry <pvince81@owncloud.com>2016-01-14 17:52:30 +0100
commitd608c37c90c308d0518d854de908ec4be5f462dc (patch)
tree35be34c59741c0184d9195c6d55263dc00990730 /apps/files_external/lib/google.php
parent3f64d37f2afd2f9a706df7495d543dccdb51c1f7 (diff)
downloadnextcloud-server-d608c37c90c308d0518d854de908ec4be5f462dc.tar.gz
nextcloud-server-d608c37c90c308d0518d854de908ec4be5f462dc.zip
Use Guzzle stream to download files from GDrive
The API library does not support streaming and always reads the full file into memory. This workaround copies the signed headers to a Guzzle request and returns the response as stream.
Diffstat (limited to 'apps/files_external/lib/google.php')
-rw-r--r--apps/files_external/lib/google.php22
1 files changed, 16 insertions, 6 deletions
diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php
index 72ebd4e821d..8a9ffaf7d37 100644
--- a/apps/files_external/lib/google.php
+++ b/apps/files_external/lib/google.php
@@ -426,13 +426,23 @@ class Google extends \OC\Files\Storage\Common {
}
if (isset($downloadUrl)) {
$request = new \Google_Http_Request($downloadUrl, 'GET', null, null);
- $httpRequest = $this->client->getAuth()->authenticatedRequest($request);
- if ($httpRequest->getResponseHttpCode() == 200) {
- $tmpFile = \OCP\Files::tmpFile($ext);
- $data = $httpRequest->getResponseBody();
- file_put_contents($tmpFile, $data);
- return fopen($tmpFile, $mode);
+ $httpRequest = $this->client->getAuth()->sign($request);
+ // the library's service doesn't support streaming, so we use Guzzle instead
+ $client = \OC::$server->getHTTPClientService()->newClient();
+ try {
+ $response = $client->get($downloadUrl, [
+ 'headers' => $httpRequest->getRequestHeaders(),
+ 'stream' => true
+ ]);
+ } catch (RequestException $e) {
+ if ($e->getResponse()->getStatusCode() === 404) {
+ return false;
+ } else {
+ throw $e;
+ }
}
+
+ return $response->getBody();
}
}
return false;