From 11ba52fbb992e32b831f4dd62449c981820cfd03 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Fri, 17 May 2024 14:49:42 +0800 Subject: [PATCH] Laravel Vapor - code sync from shipping portal to solve issue related to AWS S3 --- app/Classes/General/ExcelHandel.php | 9 ++++++++- .../Imports/ImportUpdateDebtorController.php | 14 ++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/Classes/General/ExcelHandel.php b/app/Classes/General/ExcelHandel.php index cc476b0d..dd12024b 100644 --- a/app/Classes/General/ExcelHandel.php +++ b/app/Classes/General/ExcelHandel.php @@ -4,6 +4,7 @@ namespace App\Classes\General; use Illuminate\Support\Str; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Storage; +use Carbon\Carbon; class ExcelHandel { @@ -72,7 +73,13 @@ class ExcelHandel if($filesystemDriver === 's3'){ $filePathForS3 = 'public/excels/' . $path . '/' . $filename . '.' . $extension; Storage::disk('s3')->put($filePathForS3, $exceldata); - $file_info['original']['file'] = Storage::disk('s3')->path($filePathForS3); + + $temporaryUrl = Storage::disk('s3')->temporaryUrl( + $filePathForS3, + Carbon::now()->addMinutes(10) + ); + + $file_info['original']['file'] = $temporaryUrl; //REMINDER: This is a path to AWS S3 URL (HTTPS) as a public anonymous user, NOT an internal system path } else{ $file = Storage::disk('public')->put('excels/' . $path . '/' . $filename . '.' . $extension, $exceldata); diff --git a/app/Http/Controllers/Imports/ImportUpdateDebtorController.php b/app/Http/Controllers/Imports/ImportUpdateDebtorController.php index 77ed1e92..0d21c657 100644 --- a/app/Http/Controllers/Imports/ImportUpdateDebtorController.php +++ b/app/Http/Controllers/Imports/ImportUpdateDebtorController.php @@ -14,6 +14,7 @@ use Illuminate\Support\Str; use Maatwebsite\Excel\Facades\Excel; use Maatwebsite\Excel\Excel as ExcelFileTypes; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Facades\Log; class ImportUpdateDebtorController { @@ -26,16 +27,17 @@ class ImportUpdateDebtorController $object = new DocumentObject('', $request->input('files'), '', ApprovalStatus::APPROVED, 'imports'); $file = json_decode($object->getFiles()[0])->file_info->original->file; + Log::info('ImportUpdateDebtorController file: ' . $file); + $filesystemDriver = Storage::getDefaultDriver(); if($filesystemDriver === 's3'){ - $file = Storage::disk('s3')->path('documents/' . $file); + Excel::import(new ImportsDebtor(), $file, 's3'); + } + else{ + $file = 'documents/' . $file; + Excel::import(new ImportsDebtor(), $file); } - //Shipping Portal requires the following (NOT TESTED) - // else{ - // $file = 'documents/' . $file; - // } - Excel::import(new ImportsDebtor(), $file); return []; } }