file storage: download url

This commit is contained in:
yuri
2017-02-10 15:28:41 +02:00
parent 794c7eb523
commit 2217e03fa8
5 changed files with 44 additions and 0 deletions
@@ -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);
}
}
@@ -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);
@@ -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;
}
}
@@ -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)) {
@@ -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);
}
}