_objectManager->get('Magento\Theme\Model\Uploader\Service'); try { $cssFileContent = $serviceModel->uploadCssFile('css_file_uploader'); $result = ['error' => false, 'content' => $cssFileContent['content']]; } catch (\Magento\Framework\Exception\LocalizedException $e) { $result = ['error' => true, 'message' => $e->getMessage()]; } catch (\Exception $e) { $result = ['error' => true, 'message' => __('We can\'t upload the CSS file right now.')]; $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); } $this->getResponse()->representJson( $this->_objectManager->get('Magento\Framework\Json\Helper\Data')->jsonEncode($result) ); } }