From 29300ee039adaefe8560bf3d5b573ae657b73bdd Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Mon, 29 Apr 2024 11:13:39 +0800 Subject: [PATCH] Laravel Vapor - sync code for download files in bulk from S3 to more files --- .../BulkDownloadSupplierWhiteFormsLogic.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadSupplierWhiteFormsLogic.php b/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadSupplierWhiteFormsLogic.php index fd92c097..50c8f1c8 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadSupplierWhiteFormsLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadSupplierWhiteFormsLogic.php @@ -49,8 +49,6 @@ class BulkDownloadSupplierWhiteFormsLogic $endDate = $endDate->format('d-m-Y'); $zipFileName = "currency_vendor_orders_{$startDate}_to_{$endDate}_{$companyReference}.zip"; $zip_file = "{$zipDirectory}/{$zipFileName}"; - $zipFileName2 = "currency_vendor_orders_{$startDate}_to_{$endDate}_{$companyReference}_dup.zip"; - $zip_file2 = "{$zipDirectory}/{$zipFileName2}"; $zip = new ZipArchive(); if ($zip->open($zip_file, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE)) { @@ -74,13 +72,13 @@ class BulkDownloadSupplierWhiteFormsLogic Log::info('BulkDownloadSupplierWhiteFormsLogic finished processing files count: '.count($groups)); - return redirect(Storage::disk('s3')->temporaryUrl( - $filePathForS3, - now()->addHour(), - ['ResponseContentDisposition' => 'attachment'] - )); - - // return response()->download($url); + return response()->streamDownload(function () use ($filePathForS3) { + return Storage::disk('s3')->temporaryUrl( + $filePathForS3, + Carbon::now()->addMinutes(60), + ['ResponseContentDisposition' => 'attachment'] + ); + }, $zipFileName); } else { return response()->json([