mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-23 22:44:03 +00:00
Export file directly from Laravel Vapor without going through S3 bucket
This commit is contained in:
@@ -58,7 +58,7 @@ class ExportCustomersToExcelController
|
||||
|
||||
public function paymentTransactions(Request $request){
|
||||
$exportsTransactions = new ExportsPaymentTransactions($request);
|
||||
$exportFileName = 'payment-transactions.xlsx';
|
||||
$exportFileName = 'payment-transactions.xls';
|
||||
$filesystemDriver = Storage::getDefaultDriver();
|
||||
if($filesystemDriver === 's3'){
|
||||
|
||||
@@ -68,15 +68,24 @@ class ExportCustomersToExcelController
|
||||
|
||||
//Step 2: Read and Download from S3
|
||||
$fileContent = Storage::disk('s3')->get($filePathForS3);
|
||||
$exportDirectory = storage_path('app/temp'); // Update this with the actual directory path
|
||||
if (!file_exists($exportDirectory)) {
|
||||
mkdir($exportDirectory, 0755, true);
|
||||
}
|
||||
$localPath = $exportDirectory . '/' . $exportFileName;
|
||||
file_put_contents($localPath, $fileContent);
|
||||
// $exportDirectory = storage_path('app/temp'); // Update this with the actual directory path
|
||||
// if (!file_exists($exportDirectory)) {
|
||||
// mkdir($exportDirectory, 0755, true);
|
||||
// }
|
||||
// $localPath = $exportDirectory . '/' . $exportFileName;
|
||||
// file_put_contents($localPath, $fileContent);
|
||||
|
||||
//Step 3: Return
|
||||
return response()->file($localPath, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
// //Step 3: Return
|
||||
// return response()->file($localPath, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
|
||||
$headers = [
|
||||
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'Content-Disposition' => 'attachment; filename="' . $exportFileName . '"',
|
||||
];
|
||||
|
||||
// Return the file content as a response with the headers
|
||||
return response($fileContent, 200)
|
||||
->withHeaders($headers);
|
||||
}
|
||||
else{
|
||||
$response = $exportsTransactions->download($exportFileName, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
|
||||
Reference in New Issue
Block a user