• Модуль: webdav
  • Путь к файлу: ~/bitrix/modules/webdav/classes/editdocgoogle.php
  • Класс: CWebDavEditDocGoogle
  • Вызов: CWebDavEditDocGoogle::createFile
public function createFile(array $fileData)
{
	$accessToken = $this->getAccessToken();
	$convert = is_null($fileData['convert'])? true : (bool)$fileData['convert'];

	$mimeType = $fileData['mimeType'];
	$fileSrc = $fileData['src'];
	$fileName = $fileData['name'];
	CWebDavTools::convertToUtf8($fileName);
	$fileSize = $fileData['size'];

	$http = new CHTTP();
	$http->http_timeout = 10;
	$arUrl = $http->ParseURL('https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable&convert=' . ($convert? 'true':'false'));
	$http->SetAdditionalHeaders(array(
		"Authorization" => "Bearer {$accessToken}",
		"X-Upload-Content-Type" => $mimeType,
		"X-Upload-Content-Length" => $fileSize,
	));
	$postFields = "{"title":"{$fileName}"}";
	$postContentType = 'application/json; charset=UTF-8';
	if(!$http->Query('POST', $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $postFields, $arUrl['proto'], $postContentType))
	{
		return false;
	}
	$location = $http->headers['Location'];

	$this->checkHttpResponse($http);

	// access token expired, let's get a new one and try again
	if ($http->status == "401")
	{
		//todo: invalid credential response
		return false;
	}

	// error checking
	if ($http->status != "200")
	{
		return false;
	}

	return $location;
}