file storage: download url
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user