protected function getLocationForResumableUpload(FileData $fileData) { if (!$this->checkRequiredInputParams($fileData->toArray(), array('name', 'mimeType', 'size'))) { return null; } $accessToken = $this->getAccessToken(); $fileName = $fileData->getName(); $fileName = $this->convertToUtf8($fileName); $http = new HttpClient(array('redirect' => false, 'socketTimeout' => 10, 'streamTimeout' => 30, 'version' => HttpClient::HTTP_1_1)); $http->setHeader('Content-Type', 'application/json; charset=UTF-8'); $http->setHeader('Authorization', "Bearer {$accessToken}"); $http->setHeader('X-Upload-Content-Type', $fileData->getMimeType()); $http->setHeader('X-Upload-Content-Length', $fileData->getSize()); $postFields = "{\"title\":\"{$fileName}\"}"; if ($http->post('https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable&convert=' . ($fileData->isNeedConvert() ? 'true' : 'false'), $postFields) === false) { $errorString = implode('; ', array_keys($http->getError())); $this->errorCollection->add(array(new Error($errorString, self::ERROR_HTTP_GET_LOCATION_FOR_UPLOAD))); return null; } if (!$this->checkHttpResponse($http)) { return null; } return $http->getHeaders()->get('Location'); }