diff options
Diffstat (limited to 'apps/files_external/3rdparty/google-api-php-client/src/Google/Http/MediaFileUpload.php')
-rw-r--r-- | apps/files_external/3rdparty/google-api-php-client/src/Google/Http/MediaFileUpload.php | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/apps/files_external/3rdparty/google-api-php-client/src/Google/Http/MediaFileUpload.php b/apps/files_external/3rdparty/google-api-php-client/src/Google/Http/MediaFileUpload.php index b96db84b3e7..8005db4bb48 100644 --- a/apps/files_external/3rdparty/google-api-php-client/src/Google/Http/MediaFileUpload.php +++ b/apps/files_external/3rdparty/google-api-php-client/src/Google/Http/MediaFileUpload.php @@ -51,17 +51,23 @@ class Google_Http_MediaFileUpload /** @var int $progress */ private $progress; - + /** @var Google_Client */ private $client; - + /** @var Google_Http_Request */ private $request; - + /** @var string */ private $boundary; /** + * Result code from last HTTP call + * @var int + */ + private $httpResultCode; + + /** * @param $mimeType string * @param $data string The bytes you want to upload. * @param $resumable bool @@ -89,7 +95,7 @@ class Google_Http_MediaFileUpload $this->chunkSize = $chunkSize; $this->progress = 0; $this->boundary = $boundary; - + // Process Media Request $this->process(); } @@ -102,8 +108,8 @@ class Google_Http_MediaFileUpload { $this->size = $size; } - - /** + + /** * Return the progress on the upload * @return int progress in bytes uploaded. */ @@ -111,7 +117,16 @@ class Google_Http_MediaFileUpload { return $this->progress; } - + + /** + * Return the HTTP result code from the last call made. + * @return int code + */ + public function getHttpResultCode() + { + return $this->httpResultCode; + } + /** * Send the next part of the file to upload. * @param [$chunk] the next set of bytes to send. If false will used $data passed @@ -141,22 +156,29 @@ class Google_Http_MediaFileUpload $headers, $chunk ); - $httpRequest->disableGzip(); // Disable gzip for uploads. + + if ($this->client->getClassConfig("Google_Http_Request", "enable_gzip_for_uploads")) { + $httpRequest->enableGzip(); + } else { + $httpRequest->disableGzip(); + } + $response = $this->client->getIo()->makeRequest($httpRequest); $response->setExpectedClass($this->request->getExpectedClass()); $code = $response->getResponseHttpCode(); + $this->httpResultCode = $code; if (308 == $code) { // Track the amount uploaded. $range = explode('-', $response->getResponseHeader('range')); $this->progress = $range[1] + 1; - + // Allow for changing upload URLs. $location = $response->getResponseHeader('location'); if ($location) { $this->resumeUri = $location; } - + // No problems, but upload not complete. return false; } else { @@ -177,7 +199,7 @@ class Google_Http_MediaFileUpload $meta = $this->request->getPostBody(); $meta = is_string($meta) ? json_decode($meta, true) : $meta; - + $uploadType = $this->getUploadType($meta); $this->request->setQueryParam('uploadType', $uploadType); $this->transformToUploadUrl(); @@ -214,7 +236,7 @@ class Google_Http_MediaFileUpload $this->request->setRequestHeaders($contentTypeHeader); } } - + private function transformToUploadUrl() { $base = $this->request->getBaseComponent(); @@ -265,6 +287,15 @@ class Google_Http_MediaFileUpload if (200 == $code && true == $location) { return $location; } - throw new Google_Exception("Failed to start the resumable upload"); + $message = $code; + $body = @json_decode($response->getResponseBody()); + if (!empty( $body->error->errors ) ) { + $message .= ': '; + foreach ($body->error->errors as $error) { + $message .= "{$error->domain}, {$error->message};"; + } + $message = rtrim($message, ';'); + } + throw new Google_Exception("Failed to start the resumable upload (HTTP {$message})"); } } |