protected function processActionUpload() { $this->checkRequiredFilesParams(array('file')); $this->checkRequiredPostParams(array('name')); if ($this->compareStringVersion($_SERVER['CONTENT_LENGTH'], (string) min(CUtil::unformat(ini_get('upload_max_filesize')), CUtil::unformat(ini_get('post_max_size')))) > 0) { $this->sendJsonResponse(array('status' => self::STATUS_TOO_BIG)); } if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } list($startRange, $endRange, $fileSize) = $this->getContentRange(); $tmpFileManager = new Bitrix24Disk\UploadFileManager(); $tmpFileManager->setToken($this->request->getPost('token'))->setUser($this->getUser())->setFileSize($fileSize)->setContentRange(array($startRange, $endRange)); if (!$tmpFileManager->upload($this->request->getPost('name'), $this->request->getFile('file'))) { $this->errorCollection->add($tmpFileManager->getErrors()); if ($this->errorCollection->getErrorByCode(Bitrix24Disk\TmpFile::ERROR_CLOUD_APPEND_INVALID_CHUNK_SIZE)) { $this->sendJsonResponse(array('status' => self::STATUS_CHUNK_ERROR, 'chunkSize' => $tmpFileManager->getChunkSize($this->request->getPost('name'), $fileSize))); } $this->sendJsonErrorResponse(); } $this->sendJsonSuccessResponse(array('token' => $tmpFileManager->getToken())); }
/** * Fix for Google. It does not get in metadata real size of empty file. * @param Entry $entry * @param Document\FileData $fileData * @return bool * @throws IO\FileNotFoundException * @throws \Bitrix\Main\SystemException */ protected function uploadEmptyFileFromGoogle(Entry $entry, Document\FileData $fileData) { $tmpFile = $fileData->getSrc(); $downloadedContentSize = $entry->getDownloadedContentSize(); $startRange = $downloadedContentSize; //fix for Google. It doesn't get in metadata real size of empty file. if (!$this->documentHandler->downloadFile($fileData)) { $this->errorCollection->add($this->documentHandler->getErrors()); return false; } $realFile = new IO\File($tmpFile); $contentSize = $realFile->getSize(); $entry->setContentSize($contentSize); $chunkSize = $contentSize - $downloadedContentSize; $uploadFileManager = new Bitrix24Disk\UploadFileManager(); $uploadFileManager->setTmpFileClass(TmpFile::className())->setUser($this->documentHandler->getUserId())->setFileSize($contentSize)->setContentRange(array($startRange, $startRange + $chunkSize - 1)); $tmpFileArray = \CFile::makeFileArray($tmpFile); if (!$uploadFileManager->upload($fileData->getId(), $tmpFileArray)) { $this->errorCollection->add($uploadFileManager->getErrors()); return false; } $entry->linkTmpFile(TmpFile::load(array('=TOKEN' => $uploadFileManager->getToken()))); return $entry->increaseDownloadedContentSize($chunkSize); }