• Модуль: clouds
  • Путь к файлу: ~/bitrix/modules/clouds/classes/general/storage_service_s3.php
  • Класс: CCloudStorageService_S3
  • Вызов: CCloudStorageService_S3::SaveFile
function SaveFile($arBucket, $filePath, $arFile)
{
	global $APPLICATION;

	if($arBucket["PREFIX"])
	{
		if(mb_substr($filePath, 0, mb_strlen($arBucket["PREFIX"]) + 2) != "/".$arBucket["PREFIX"]."/")
			$filePath = "/".$arBucket["PREFIX"]."/".ltrim($filePath, "/");
	}
	$filePath = CCloudUtil::URLEncode($filePath, "UTF-8", true);

	$additional_headers = array();
	if($this->_public)
		$additional_headers["x-amz-acl"] = "public-read";
	$additional_headers["Content-Type"] = $arFile["type"];
	$additional_headers["Content-Length"] = (array_key_exists("content", $arFile)? strlen($arFile["content"]): filesize($arFile["tmp_name"]));

	if (
		defined("BX_CLOUDS_COUNTERS_DEBUG")
		&& !preg_match(BX_CLOUDS_COUNTERS_DEBUG, $filePath)
	)
	{
		CCloudsDebug::getInstance("put")->startAction($filePath);
	}

	$this->SetLocation($arBucket["LOCATION"]);
	$this->SendRequest(
		$arBucket["SETTINGS"],
		'PUT',
		$arBucket["BUCKET"],
		$filePath,
		'',
		(array_key_exists("content", $arFile)? $arFile["content"]: fopen($arFile["tmp_name"], "rb")),
		$additional_headers
	);

	if (
		defined("BX_CLOUDS_COUNTERS_DEBUG")
		&& !preg_match(BX_CLOUDS_COUNTERS_DEBUG, $filePath)
	)
	{
		CCloudsDebug::getInstance("put")->endAction();
	}

	if (
		defined("BX_CLOUDS_COUNTERS_DEBUG")
		&& $this->status == 200
		&& !preg_match(BX_CLOUDS_COUNTERS_DEBUG, $filePath)
	)
	{
		CCloudsDebug::getInstance()->startAction($filePath);
	}

	if($this->status == 200)
	{
		return true;
	}
	elseif ($this->checkForTokenExpiration($this->status, $this->result))
	{
		$this->tokenHasExpired = true;
		return false;
	}
	elseif($this->status == 403)
	{
		if (defined("BX_CLOUDS_ERROR_DEBUG"))
		{
			AddMessage2Log($this);
		}
		return false;
	}
	else
	{
		$APPLICATION->ResetException();
		if (defined("BX_CLOUDS_ERROR_DEBUG"))
		{
			AddMessage2Log($this);
		}
		return false;
	}
}