Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib/google.php')
-rw-r--r--apps/files_external/lib/google.php26
1 files changed, 18 insertions, 8 deletions
diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php
index eba2ee7f9b5..8a9ffaf7d37 100644
--- a/apps/files_external/lib/google.php
+++ b/apps/files_external/lib/google.php
@@ -10,11 +10,11 @@
* @author Morris Jobke <hey@morrisjobke.de>
* @author Philipp Kapfer <philipp.kapfer@gmx.at>
* @author Robin Appelman <icewind@owncloud.com>
- * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
* @author Thomas Müller <thomas.mueller@tmit.eu>
* @author Vincent Petry <pvince81@owncloud.com>
*
- * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
@@ -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;