From 69980ef064e323208170275cd9dca3124f275596 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Mon, 29 Apr 2024 13:28:25 +0800 Subject: [PATCH] Laravel Vapor - sync code for download files in bulk from S3 to more files --- .../BulkDownloadSupplierWhiteFormsLogic.php | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadSupplierWhiteFormsLogic.php b/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadSupplierWhiteFormsLogic.php index a6e29b83..61cce5ae 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadSupplierWhiteFormsLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadSupplierWhiteFormsLogic.php @@ -73,14 +73,27 @@ class BulkDownloadSupplierWhiteFormsLogic Log::info('BulkDownloadSupplierWhiteFormsLogic finished processing files count: '.count($groups)); - return response()->streamDownload(function () use ($filePathForS3) { + // return response()->streamDownload(function () use ($filePathForS3) { + // $temporaryUrl = Storage::disk('s3')->temporaryUrl( + // $filePathForS3, + // Carbon::now()->addMinutes(60) + // ); + // $response = Http::get($temporaryUrl); + // echo $response->getBody()->getContents(); + // }, $zipFileName); + + return response()->stream(function () use ($filePathForS3) { $temporaryUrl = Storage::disk('s3')->temporaryUrl( $filePathForS3, Carbon::now()->addMinutes(60) ); - $response = Http::get($temporaryUrl); - echo $response->getBody()->getContents(); - }, $zipFileName); + $fileStream = fopen($temporaryUrl, 'r'); + fpassthru($fileStream); + fclose($fileStream); + }, 200, [ + 'Content-Type' => 'application/octet-stream', + 'Content-Disposition' => 'attachment', + ]); } else { return response()->json([