190 $bucket = \CCloudStorage::findBucketForFile(array(
'FILE_SIZE' => $file[
'size'],
'MODULE_ID' => $this->moduleId), $file[
"name"] ??
'');
200 $absPath = \CTempFile::getAbsoluteRoot();
201 $relativePath =
$path;
202 if (mb_substr(
$path, 0, mb_strlen($absPath)) == $absPath && mb_strpos(
$path,
"/bxu/") > 0)
203 $relativePath = mb_substr(
$path, mb_strpos(
$path,
"/bxu/"));
204 $subdir = explode(
"/", trim($relativePath,
"/"));
205 $filename = array_pop($subdir);
208 \Bitrix\Main\Application::getInstance()->getSession()[
"upload_tmp"] = array();
213 $relativePath = \Bitrix\Main\Application::getInstance()->getSession()[
"upload_tmp"][
$path] =\CCloudTempFile::GetDirectoryName($bucket, 12).$filename;
217 $relativePath = \Bitrix\Main\Application::getInstance()->getSession()[
"upload_tmp"][
$path];
220 $upload = new \CCloudStorageUpload($relativePath);
222 if(!$upload->isStarted() && !$upload->start($bucket->ID, $file[
"size"], $file[
"type"]))
224 $result->addError(
new Error(
Loc::getMessage(
"BXU_FileTransferIntoTheCloudIsFailed"),
"BXU346.2"));
226 else if (!($fileContent = \
Bitrix\Main\
IO\File::getFileContents($file[
"tmp_name"])))
234 while ($upload->hasRetries())
236 if (method_exists($upload,
"part") && $upload->part($fileContent, ($file[
"number"] ?? 0)) ||
237 !method_exists($upload,
"part") && $upload->next($fileContent))
246 $result->addError(
new Error(
"Could not upload file for {$fails} times.",
"BXU346.4"));
248 else if (isset($file[
"count"]) && $upload->GetPartCount() < $file[
"count"])
251 else if (!$upload->finish())
253 $result->addError(
new Error(
"Could not resume file transfer.",
"BXU346.5"));
261 $result->setData(array(
262 "tmp_name" => $bucket->getFileSRC($relativePath),
263 "size" => $file[
"size"],
264 "type" => $file[
"type"],
265 "finished" => $finished
272 $result = parent::copy(
$path, $file);
273 if ($result->isSuccess())
275 if (!array_key_exists(
'start', $file))
277 $res = $result->getData();
278 $file[
"tmp_name"] = $res[
"tmp_name"];
279 $file[
"size"] = $res[
"size"];
280 $file[
"type"] = $res[
"type"];
281 $info = (new \Bitrix\Main\File\Image($file[
"tmp_name"]))->getInfo();
284 $file[
"width"] = $info->getWidth();
285 $file[
"height"] = $info->getHeight();
292 if ($bucket = $this->findBucket($file))
294 unset($file[
"count"]);
295 if (($r = $this->
moveIntoCloud($bucket, $file[
"tmp_name"], $file)) && $r->isSuccess())
297 $res = $r->getData();
298 $result->setData(array(
299 "size" => $file[
"size"],
300 "file_size" => $file[
"size"],
301 "tmp_name" => $res[
"tmp_name"],
302 "type" => $file[
"type"],
303 "width" => $file[
"width"],
304 "height" => $file[
"height"],
305 "bucketId" => $bucket->ID
310 $result->addErrors($r->getErrors());
315 else if ($file[
"start"] <= 0)
317 $res = $result->getData();
318 if (($info = (
new \
Bitrix\Main\
File\Image($file[
"tmp_name"]))->getInfo()))
320 $file[
"width"] = $info->getWidth();
321 $file[
"height"] = $info->getHeight();
322 $result->setData(array_merge($res, [
"width" => $file[
"width"],
"height" => $file[
"height"]]));
335 if ($bucket = $this->findBucket(array(
336 "name" => $file[
"~name"],
337 "size" => $file[
"~size"],
340 if (($result = $this->
moveIntoCloud($bucket,
$path, array_merge($file, array(
"size" => $file[
"~size"])))) &&
341 $result->isSuccess() && ($res = $result->getData()) && $res[
"finished"] ===
true)
343 $res = $result->getData();
344 $result->setData(array(
345 "size" => $file[
"~size"],
346 "file_size" => $file[
"~size"],
347 "tmp_name" => $res[
"tmp_name"],
348 "type" => $file[
"type"],
349 "bucketId" => $bucket->ID
355 $result = parent::copyChunk(
$path, $file);