diff --git a/application/Espo/Core/FileStorage/Manager.php b/application/Espo/Core/FileStorage/Manager.php index 403727c9ed..d09ab3bfb7 100644 --- a/application/Espo/Core/FileStorage/Manager.php +++ b/application/Espo/Core/FileStorage/Manager.php @@ -100,4 +100,16 @@ class Manager $implementation = $this->getImplementation($attachment->get('storage')); return $implementation->getLocalFilePath($attachment); } + + public function hasDownloadUrl(Attachment $attachment) + { + $implementation = $this->getImplementation($attachment->get('storage')); + return $implementation->hasDownloadUrl($attachment); + } + + public function getDownloadUrl(Attachment $attachment) + { + $implementation = $this->getImplementation($attachment->get('storage')); + return $implementation->getDownloadUrl($attachment); + } } diff --git a/application/Espo/Core/FileStorage/Storages/Base.php b/application/Espo/Core/FileStorage/Storages/Base.php index 978b2e792f..698027050a 100644 --- a/application/Espo/Core/FileStorage/Storages/Base.php +++ b/application/Espo/Core/FileStorage/Storages/Base.php @@ -73,6 +73,10 @@ abstract class Base implements Injectable return $this->dependencyList; } + abstract public function hasDownloadUrl(\Espo\Entities\Attachment $attachment); + + abstract public function getDownloadUrl(\Espo\Entities\Attachment $attachment); + abstract public function unlink(\Espo\Entities\Attachment $attachment); abstract public function getContents(\Espo\Entities\Attachment $attachment); diff --git a/application/Espo/Core/FileStorage/Storages/EspoUploadDir.php b/application/Espo/Core/FileStorage/Storages/EspoUploadDir.php index 6da52d84ee..ab22e8b3d8 100644 --- a/application/Espo/Core/FileStorage/Storages/EspoUploadDir.php +++ b/application/Espo/Core/FileStorage/Storages/EspoUploadDir.php @@ -31,6 +31,8 @@ namespace Espo\Core\FileStorage\Storages; use \Espo\Entities\Attachment; +use \Espo\Core\Exceptions\Error; + class EspoUploadDir extends Base { protected $dependencyList = ['fileManager']; @@ -70,4 +72,14 @@ class EspoUploadDir extends Base $sourceId = $attachment->getSourceId(); return 'data/upload/' . $sourceId; } + + public function getDownloadUrl(Attachment $attachment) + { + throw new Error(); + } + + public function hasDownloadUrl(Attachment $attachment) + { + return false; + } } diff --git a/application/Espo/EntryPoints/Download.php b/application/Espo/EntryPoints/Download.php index 203c4d9ee2..d9f584d38a 100644 --- a/application/Espo/EntryPoints/Download.php +++ b/application/Espo/EntryPoints/Download.php @@ -67,6 +67,12 @@ class Download extends \Espo\Core\EntryPoints\Base $sourceId = $attachment->getSourceId(); + if ($this->getEntityManager()->getRepository('Attachment')->hasDownloadUrl($attachment)) { + $downloadUrl = $this->getEntityManager()->getRepository('Attachment')->getDownloadUrl($attachment); + header('Location: ' . $downloadUrl); + exit; + } + $fileName = $this->getEntityManager()->getRepository('Attachment')->getFilePath($attachment); if (!file_exists($fileName)) { diff --git a/application/Espo/Repositories/Attachment.php b/application/Espo/Repositories/Attachment.php index e79ce09819..13482e2ef4 100644 --- a/application/Espo/Repositories/Attachment.php +++ b/application/Espo/Repositories/Attachment.php @@ -116,4 +116,14 @@ class Attachment extends \Espo\Core\ORM\Repositories\RDB { return $this->getFileStorageManager()->getLocalFilePath($entity); } + + public function hasDownloadUrl(Entity $entity) + { + return $this->getFileStorageManager()->hasDownloadUrl($entity); + } + + public function getDownloadUrl(Entity $entity) + { + return $this->getFileStorageManager()->getDownloadUrl($entity); + } }