From de8fb374abe80a4b49146bbeeb49cea92bfa6e2e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 14 May 2021 19:43:06 +1000 Subject: [PATCH] Fixes for S3 storage and delivery notes --- app/Http/Controllers/InvoiceController.php | 1 - app/Services/Invoice/GenerateDeliveryNote.php | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 885d4798be..bf887607c1 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -849,7 +849,6 @@ class InvoiceController extends BaseController try { $file = public_path("storage/{$file_path}"); - return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache']); } catch (\Exception $e) { return response(['message' => 'Oops, something went wrong. Make sure you have symlink to storage/ in public/ directory.'], 500); diff --git a/app/Services/Invoice/GenerateDeliveryNote.php b/app/Services/Invoice/GenerateDeliveryNote.php index b6c93fa494..e7feb45050 100644 --- a/app/Services/Invoice/GenerateDeliveryNote.php +++ b/app/Services/Invoice/GenerateDeliveryNote.php @@ -20,6 +20,7 @@ use App\Services\PdfMaker\PdfMaker as PdfMakerService; use App\Utils\HostedPDF\NinjaPdf; use App\Utils\HtmlEngine; use App\Utils\PhantomJS\Phantom; +use App\Utils\TempFile; use App\Utils\Traits\MakesHash; use App\Utils\Traits\Pdf\PdfMaker; use Illuminate\Support\Facades\Storage; @@ -105,6 +106,10 @@ class GenerateDeliveryNote Storage::disk($this->disk)->put($file_path, $pdf); + /* Copy from remote disk to local when using cloud file storage. */ + if(config('filesystems.default') == 's3') + return TempFile::path(Storage::disk($disk)->url($file_path)); + return $file_path; } }