/** * Check if gallery entry content is valid * * @param ContentInterface $fileContent * @throws InputException * @return bool */ public function isValid(ContentInterface $fileContent) { $decodedContent = @base64_decode($fileContent->getFileData(), true); if (empty($decodedContent)) { throw new InputException(__('Provided content must be valid base64 encoded data.')); } if (!$this->isFileNameValid($fileContent->getName())) { throw new InputException(__('Provided file name contains forbidden characters.')); } return true; }
/** * Decode base64 encoded content and save it in system tmp folder * * @param ContentInterface $fileContent * @return array */ protected function decodeContent(ContentInterface $fileContent) { $tmpFileName = $this->getTmpFileName(); $fileSize = $this->systemTmpDirectory->writeFile($tmpFileName, base64_decode($fileContent->getFileData())); return ['name' => $fileContent->getName(), 'type' => self::DEFAULT_MIME_TYPE, 'tmp_name' => $this->systemTmpDirectory->getAbsolutePath($tmpFileName), 'error' => 0, 'size' => $fileSize]; }