- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/document/upload/googleresumableupload.php
- Класс: BitrixDiskDocumentUploadGoogleResumableUpload
- Вызов: GoogleResumableUpload::getLocationForResumableUpload
protected function getLocationForResumableUpload()
{
if(!$this->checkRequiredInputParams($this->fileData->toArray(), array(
'name', 'mimeType', 'size',
)))
{
return null;
}
$fileName = $this->fileData->getName();
$fileName = $this->convertToUtf8($fileName);
$http = new HttpClient(array(
'redirect' => false,
'socketTimeout' => 10,
'streamTimeout' => 30,
'version' => HttpClient::HTTP_1_1,
));
$this->setBearer($http);
$http->setHeader('Content-Type', 'application/json; charset=UTF-8');
$http->setHeader('X-Upload-Content-Type', $this->fileData->getMimeType());
$http->setHeader('X-Upload-Content-Length', $this->fileData->getSize());
$postFields = "{"name":"{$fileName}"}";
if($this->fileData->isNeededToConvert())
{
$googleMimeType = GoogleHandler::getInternalMimeTypeByExtension(getFileExtension($this->fileData->getName()));
$postFields = "{"name":"{$fileName}", "mimeType": "{$googleMimeType}"}";
}
if($http->post(GoogleHandler::API_URL_UPLOAD_V3 . '/files?uploadType=resumable&fields=id,webViewLink,version,createdTime,modifiedTime', $postFields) === false)
{
$errorString = implode('; ', array_keys($http->getError()));
$this->errorCollection[] = new Error(
$errorString, self::ERROR_HTTP_GET_LOCATION_FOR_UPLOAD
);
return null;
}
if(!$this->documentHandler->checkHttpResponse($http))
{
return null;
}
return $http->getHeaders()->get('Location');
}