From b760771c8f25242e7f311d7d9f8b26223be9552c Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Fri, 29 Dec 2023 23:16:42 +0800 Subject: [PATCH] Laravel Vapor - Fix path to upload documents to S3 bucket with dynamic path --- .../Documents/ControllersLogic/RenderDocumentLogic.php | 2 +- .../Documents/DataTransferObjects/DocumentObject.php | 7 +------ .../Modules/Documents/Services/ConvertsBase64ToFile.php | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/Classes/Modules/Documents/ControllersLogic/RenderDocumentLogic.php b/app/Classes/Modules/Documents/ControllersLogic/RenderDocumentLogic.php index 6d7f5afc..0146a2f7 100644 --- a/app/Classes/Modules/Documents/ControllersLogic/RenderDocumentLogic.php +++ b/app/Classes/Modules/Documents/ControllersLogic/RenderDocumentLogic.php @@ -60,7 +60,7 @@ class RenderDocumentLogic extends AbstractControllerLogic { throw new ResourceNotFoundException(); } - return $this->response(['src' => explode('.', $file)[1] == 'pdf' ? chunk_split(base64_encode(Storage::disk('documents')->get($file))) : Storage::disk('documents')->get($file) ]); + return $this->response(['src' => explode('.', $file)[1] == 'pdf' ? chunk_split(base64_encode(Storage::disk('s3')->get($file))) : Storage::disk('s3')->get($file) ]); } else{ if(!Storage::disk('documents')->exists($file)) diff --git a/app/Classes/Modules/Documents/DataTransferObjects/DocumentObject.php b/app/Classes/Modules/Documents/DataTransferObjects/DocumentObject.php index 3f862417..812a12ab 100644 --- a/app/Classes/Modules/Documents/DataTransferObjects/DocumentObject.php +++ b/app/Classes/Modules/Documents/DataTransferObjects/DocumentObject.php @@ -73,12 +73,7 @@ class DocumentObject implements DataTransferObject */ public function getFiles(): array { - $filePath = $this->path; - $filesystemDriver = Storage::getDefaultDriver(); - if($filesystemDriver == 's3'){ - $filePath = 'documents/'.$this->path; - } - return (new ConvertsBase64ToFile($filePath))->convert($this->files); + return (new ConvertsBase64ToFile($this->path))->convert($this->files); } diff --git a/app/Classes/Modules/Documents/Services/ConvertsBase64ToFile.php b/app/Classes/Modules/Documents/Services/ConvertsBase64ToFile.php index 9f094065..dc9c2210 100644 --- a/app/Classes/Modules/Documents/Services/ConvertsBase64ToFile.php +++ b/app/Classes/Modules/Documents/Services/ConvertsBase64ToFile.php @@ -101,7 +101,7 @@ class ConvertsBase64ToFile $filesystemDriver = Storage::getDefaultDriver(); if($filesystemDriver == 's3'){ - $filePath = $this->path.'/'.$file->getFileName().$suffix.'.'.$file->getExtension(); + $filePath = 'documents/'.$this->path.'/'.$file->getFileName().$suffix.'.'.$file->getExtension(); Storage::put($filePath, $file->getDecodedData(), 's3'); return $filePath; }