/** * Upload js file * * @param string $file - Key in the $_FILES array * @return array * @throws \Magento\Framework\Exception\LocalizedException */ public function uploadJsFile($file) { /** @var $fileUploader \Magento\MediaStorage\Model\File\Uploader */ $fileUploader = $this->_uploaderFactory->create(['fileId' => $file]); $fileUploader->setAllowedExtensions(['js']); $fileUploader->setAllowRenameFiles(true); $fileUploader->setAllowCreateFolders(true); $isValidFileSize = $this->_validateFileSize($fileUploader->getFileSize(), $this->getJsUploadMaxSize()); if (!$isValidFileSize) { throw new \Magento\Framework\Exception\LocalizedException(__('The JS file must be less than %1M.', $this->getJsUploadMaxSizeInMb())); } $file = $fileUploader->validateFile(); return ['filename' => $file['name'], 'content' => $this->getFileContent($file['tmp_name'])]; }