rawFactory->create(); try { $attachment = $this->conversations->getAttachmentForAdmin((int)$this->getRequest()->getParam('id')); if (!$attachment) { throw new \Magento\Framework\Exception\LocalizedException(__('The requested image is not available.')); } $filename = str_replace(["\r", "\n"], '', (string)$attachment['original_name']); return $result->setHeader('Content-Type', (string)$attachment['mime_type'], true) ->setHeader('Content-Length', (string)$attachment['file_size'], true) ->setHeader('Content-Disposition', 'inline; filename="' . addcslashes($filename, '"\\') . '"', true) ->setHeader('X-Content-Type-Options', 'nosniff', true) ->setContents((string)file_get_contents($this->storage->getAbsolutePath((string)$attachment['storage_path']))); } catch (\Throwable) { return $result->setHttpResponseCode(404)->setContents('Not found'); } } }