From b5d247909848e639b59bfb246220258f4f10d652 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 5 Nov 2024 21:51:48 +1100 Subject: [PATCH] Better catching failures when Stream::read doesnt returns null --- .env.example | 1 + app/Classes/File/File.php | 19 ++++++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.env.example b/.env.example index a669ca4..a004246 100644 --- a/.env.example +++ b/.env.example @@ -20,6 +20,7 @@ QUEUE_CONNECTION=database SESSION_DRIVER=file SESSION_LIFETIME=120 +FILESYSTEM_DISK=s3 AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_BUCKET= diff --git a/app/Classes/File/File.php b/app/Classes/File/File.php index 0d83980..20cc0c9 100644 --- a/app/Classes/File/File.php +++ b/app/Classes/File/File.php @@ -86,21 +86,18 @@ final class File extends Send $this->size = $this->f->size; // If sending file is a File::class, then our file is s3 - if ($this->nameas && $this->f instanceof FileModel) { - $this->fd = Storage::readStream($this->f->rel_name); + $this->fd = ($this->nameas && $this->f instanceof FileModel) + ? Storage::readStream($this->f->rel_name) + : fopen($this->full_name,'rb'); - } else { - $this->fd = fopen($this->full_name,'rb'); + if (! $this->fd) { + Log::error(sprintf('%s:! Unable to open file [%s] for reading',self::LOGKEY,$this->full_name)); - if (! $this->fd) { - Log::error(sprintf('%s:! Unable to open file [%s] for reading',self::LOGKEY,$this->full_name)); - - return FALSE; - } - - Log::info(sprintf('%s:= File [%s] opened with size [%d]',self::LOGKEY,$this->full_name,$this->size)); + return FALSE; } + Log::info(sprintf('%s:= File [%s] opened with size [%d]',self::LOGKEY,$this->full_name,$this->size)); + return TRUE; }