- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/ui/uploader/storage.php
- Класс: BitrixMainUIUploaderCloudStorage
- Вызов: CloudStorage::moveIntoCloud
protected function moveIntoCloud(CCloudStorageBucket $bucket, $path, $file)
{
$result = new Result();
$absPath = CTempFile::getAbsoluteRoot();
$relativePath = $path;
if (mb_substr($path, 0, mb_strlen($absPath)) == $absPath && mb_strpos($path, "/bxu/") > 0)
$relativePath = mb_substr($path, mb_strpos($path, "/bxu/"));
$subdir = explode("/", trim($relativePath, "/"));
$filename = array_pop($subdir);
if (!isset(BitrixMainApplication::getInstance()->getSession()["upload_tmp"]))
{
BitrixMainApplication::getInstance()->getSession()["upload_tmp"] = array();
}
if (!isset(BitrixMainApplication::getInstance()->getSession()["upload_tmp"][$path]))
{
$relativePath = BitrixMainApplication::getInstance()->getSession()["upload_tmp"][$path] =CCloudTempFile::GetDirectoryName($bucket, 12).$filename;
}
else
{
$relativePath = BitrixMainApplication::getInstance()->getSession()["upload_tmp"][$path];
}
$upload = new CCloudStorageUpload($relativePath);
$finished = false;
if(!$upload->isStarted() && !$upload->start($bucket->ID, $file["size"], $file["type"]))
{
$result->addError(new Error(Loc::getMessage("BXU_FileTransferIntoTheCloudIsFailed"), "BXU346.2"));
}
else if (!($fileContent = BitrixMainIOFile::getFileContents($file["tmp_name"])))
{
$result->addError(new Error(Loc::getMessage("BXU_FileIsFailedToRead"), "BXU346.3"));
}
else
{
$fails = 0;
$success = false;
while ($upload->hasRetries())
{
if (method_exists($upload, "part") && $upload->part($fileContent, ($file["number"] ?? 0)) ||
!method_exists($upload, "part") && $upload->next($fileContent))
{
$success = true;
break;
}
$fails++;
}
if (!$success)
{
$result->addError(new Error("Could not upload file for {$fails} times.", "BXU346.4"));
}
else if (isset($file["count"]) && $upload->GetPartCount() < $file["count"])
{
}
else if (!$upload->finish())
{
$result->addError(new Error("Could not resume file transfer.", "BXU346.5"));
}
else
{
$finished = true;
}
}
$result->setData(array(
"tmp_name" => $bucket->getFileSRC($relativePath),
"size" => $file["size"],
"type" => $file["type"],
"finished" => $finished
));
return $result;
}