• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/tradingplatform/vk/api/photouploader.php
  • Класс: BitrixSaleTradingPlatformVkApiPhotoUploader
  • Вызов: PhotoUploader::uploadHttp
private function uploadHttp($data, $uploadServer)
{
	$postParams = array(
		"url" => $data[$this->params['keyPhotoUrl']],
		"filename" => IOPath::getName($data[$this->params['keyPhotoUrl']]),
		"param_name" => 'file',
	);

	$http = new HttpClient();

	$boundary = md5(rand() . time());
	$file = $this->getFile($postParams["url"]);

	$request = '--' . $boundary . "rn";
	$request .= 'Content-Disposition: form-data; name="' . $postParams["param_name"] . '"; filename="' . $postParams["filename"] . '"' . "rn";
	$request .= 'Content-Type: application/octet-stream' . "rnrn";
	$request .= $file . "rn";
	$request .= '--' . $boundary . "--rn";
	
	$http->setHeader('Content-type', 'multipart/form-data; boundary=' . $boundary);
	$http->setHeader('Content-length', BitrixMainTextBinaryString::getLength($request));
	
	$this->logger->addLog("Upload photo HTTP params", [
		'SERVER' => $uploadServer,
		'PARAMS' => $postParams,
		'FILE_OK' => $file ? 'Y' : 'N',
	]);
	$result = $http->post($uploadServer, $request);

	$result = Json::decode($result);
	$this->logger->addLog("Upload photo HTTP response", $result);

//		check http upload status. If error - need skip this image
	if($result['error'])
	{
//			get error code from error string
		$this->logger->addError(
			explode(':', $result['error'])[0] . '_' . $this->type,
			$data[$this->params['keyReference']]
		);
		
		return false;
	}

//		check TIMER if set
	if($this->timer !== null && !$this->timer->check())
	{
		throw new TimeIsOverException();
	}
	
	return $result;
}