diff --git a/alpha/apps/kaltura/lib/exceptions/kUploadTokenException.php b/alpha/apps/kaltura/lib/exceptions/kUploadTokenException.php index 8096ff09ade..5ecc4b61190 100644 --- a/alpha/apps/kaltura/lib/exceptions/kUploadTokenException.php +++ b/alpha/apps/kaltura/lib/exceptions/kUploadTokenException.php @@ -26,4 +26,6 @@ class kUploadTokenException extends kCoreException const UPLOAD_TOKEN_MAX_AUTO_FINALIZE_RETRIES_REACHED = "UPLOAD_TOKEN_MAX_AUTO_FINALIZE_RETRIES_REACHED"; const UPLOAD_TOKEN_AUTO_FINALIZE_CACHE_NOT_INITIALIZED = "UPLOAD_TOKEN_AUTO_FINALIZE_CACHE_NOT_INITIALIZED"; + + const UPLOAD_TOKEN_FILE_IS_EMPTY = "UPLOAD_TOKEN_FILE_IS_EMPTY"; } \ No newline at end of file diff --git a/alpha/apps/kaltura/lib/kUploadTokenMgr.php b/alpha/apps/kaltura/lib/kUploadTokenMgr.php index d3d21f28c78..a33c69fa351 100644 --- a/alpha/apps/kaltura/lib/kUploadTokenMgr.php +++ b/alpha/apps/kaltura/lib/kUploadTokenMgr.php @@ -91,12 +91,19 @@ public function uploadFileToToken($fileData, $resume = false, $resumeAt = -1) try { - $this->checkIfFileIsValid($fileData); + $this->checkIfFileIsValid($fileData, $resumeAt, $this->_finalChunk); } catch(kUploadTokenException $ex) { + if($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_FILE_IS_EMPTY) + { + return; + } + if(!$resume && $this->_finalChunk) + { kFlowHelper::handleUploadFailed($this->_uploadToken); + } $this->tryMoveToErrors($fileData); throw $ex; @@ -147,7 +154,7 @@ public function deleteUploadToken() * Validate the file data * @param file $fileData */ - protected function checkIfFileIsValid($fileData) + protected function checkIfFileIsValid($fileData, $resumeAt, $finalChunk) { // check file name $fileName = isset($fileData['name']) ? $fileData['name'] : null; @@ -175,6 +182,15 @@ protected function checkIfFileIsValid($fileData) KalturaLog::log($msg . ' ' . print_r($fileData, true)); throw new kUploadTokenException($msg, kUploadTokenException::UPLOAD_TOKEN_FILE_IS_NOT_VALID); } + + $tempFileSize = kFile::fileSize($tempPath); + if($tempFileSize == 0 && !$finalChunk && $resumeAt > 0) + { + $msg = "The uploaded file has 0 bytes, file will be dismissed for token id [{$this->_uploadToken->getId()}]"; + KalturaLog::log($msg . ' ' . print_r($fileData, true)); + kFile::doDeleteFile($tempPath); + throw new kUploadTokenException($msg, kUploadTokenException::UPLOAD_TOKEN_FILE_IS_EMPTY); + } } /**