- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/document/cloudimport/importmanager.php
- Класс: BitrixDiskDocumentCloudImportImportManager
- Вызов: ImportManager::uploadChunk
public function uploadChunk(Entry $entry)
{
$tmpFile = CTempFile::getFileName(uniqid('_wd', true));
checkDirPath($tmpFile);
$fileData = new DocumentFileData;
$fileData->setId($entry->getServiceObjectId());
$fileData->setMimeType($entry->getMimeType());
$fileData->setSrc($tmpFile);
$chunkSize = self::CHUNK_SIZE;
$downloadedContentSize = $entry->getDownloadedContentSize();
$contentSize = $entry->getContentSize();
if($contentSize == 0 && $this->documentHandler instanceof DocumentGoogleHandler)
{
return $this->uploadEmptyFileFromGoogle($entry, $fileData);
}
if($contentSize - $downloadedContentSize < $chunkSize)
{
$chunkSize = $contentSize - $downloadedContentSize;
}
$startRange = $downloadedContentSize;
if(!$this->documentHandler->downloadPartFile($fileData, $startRange, $chunkSize))
{
$this->errorCollection->add($this->documentHandler->getErrors());
return false;
}
$token = null;
if($entry->getTmpFile() && $entry->getTmpFile()->getToken())
{
//todo it's strange, fix it
$token = $entry->getTmpFile()->getToken();
}
$uploadFileManager = $this->uploadFileManager;
$uploadFileManager
->setFileSize($contentSize)
->setEntry($entry)
->setToken($token)
->setContentRange(array($startRange, $startRange + $chunkSize - 1))
;
$tmpFileArray = CFile::makeFileArray($tmpFile);
if(!$uploadFileManager->upload($fileData->getId(), $tmpFileArray))
{
$this->errorCollection->add($uploadFileManager->getErrors());
return false;
}
if($token === null)
{
$entry->linkTmpFile(TmpFile::load(array('=TOKEN' => $uploadFileManager->getToken())));
}
return $entry->increaseDownloadedContentSize($chunkSize);
}