Export pdf file from Laravel Vapor through S3 bucket

This commit is contained in:
Dillon Ngo
2024-06-18 11:53:45 +08:00
parent fcaee29be3
commit 52fa577c4b
2 changed files with 26 additions and 3 deletions
@@ -8,6 +8,8 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\General\AWSS3Helper;
use Illuminate\Support\Facades\Storage;
class DownloadMockUpWhiteFormPdfLogic
{
@@ -56,6 +58,14 @@ class DownloadMockUpWhiteFormPdfLogic
DB::rollBack();
return $pdf->stream('MockUpWhiteForm.pdf');
$exportFileName = 'MockUpWhiteForm.pdf';
$filesystemDriver = Storage::getDefaultDriver();
if($filesystemDriver === 's3'){
$pdfContent = $pdf->output();
AWSS3Helper::S3PDF($exportFileName, $pdfContent);
}
else{
return $pdf->stream($exportFileName);
}
}
}
@@ -150,9 +150,22 @@
return payment.id
});
window.open(this.route('whiteForm.mockUp', this.supplier.id)+'?rate='+this.parameters.rate+'&payments='+JSON.stringify(paymentIds), '_blank');
let url = this.route('whiteForm.mockUp', this.supplier.id)+'?rate='+this.parameters.rate+'&payments='+JSON.stringify(paymentIds);
if(window.LARAVEL_VAPOR_ENABLED){
return fetch(url, {
method: 'GET',
responseType: 'json',
}).then(response => {
if (response.src) {
window.location.href = response.src;
}
});
}
else{
window.open(url, '_blank');
}
}
},
mixins: [FormHandler]
}
</script>
</script>