- Модуль: webdav
- Путь к файлу: ~/bitrix/modules/webdav/classes/editdocgoogle.php
- Класс: CWebDavEditDocGoogle
- Вызов: CWebDavEditDocGoogle::createBlankFile
public function createBlankFile(array $fileData)
{
$accessToken = $this->getAccessToken();
$googleMimeType = $this->getInternalMimeTypeListByExtension(getFileExtension($fileData['name']));
$fileName = getFileNameWithoutExtension($fileData['name']);
CWebDavTools::convertToUtf8($fileName);
if(!$googleMimeType)
{
return false;
}
$http = new CHTTP();
$http->http_timeout = 10;
$arUrl = $http->ParseURL('https://www.googleapis.com/drive/v2/files');
$http->SetAdditionalHeaders(array(
"Authorization" => "Bearer {$accessToken}",
//"X-Upload-Content-Type" => $mimeType,
));
$postFields = "{"title":"{$fileName}","mimeType":"{$googleMimeType}"}";
$postContentType = 'application/json; charset=UTF-8';
if(!$http->Query('POST', $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $postFields, $arUrl['proto'], $postContentType))
{
return false;
}
$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;
}
$finalOutput = json_decode($http->result);
//last signed user must delete file from google drive
$this->insertPermission(array('link' => $finalOutput->alternateLink, 'id' => $finalOutput->id));
return array('link' => $finalOutput->alternateLink, 'id' => $finalOutput->id);
}