Export pdf file from Laravel Vapor through S3 bucket

This commit is contained in:
Dillon Ngo
2024-06-18 11:38:43 +08:00
parent 38aa670528
commit fcaee29be3
8 changed files with 106 additions and 31 deletions
+23 -5
View File
@@ -2,19 +2,18 @@
namespace App\Classes\General;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Carbon\Carbon;
use Maatwebsite\Excel\Concerns\Exportable;
class AWSS3Helper
{
/**
* @param string $methodName
* @param string $exportFileName
* @param Exportable $exportableObject
* @return string
*/
static function S3($exportFileName, $exportableObject){
static function S3Exportable($exportFileName, $exportableObject){
//Step 1: Upload to S3
$filePathForS3 = 'temp/' . $exportFileName;
$exportableObject->store($filePathForS3, 's3');
@@ -28,4 +27,23 @@ class AWSS3Helper
return $temporaryUrl;
}
/**
* @param string $exportFileName
* @param string|resource $contents
* @return string
*/
static function S3PDF($exportFileName, $contents){
//Step 1: Upload to S3
$filePathForS3 = 'temp/' . $exportFileName;
Storage::disk('s3')->put($filePathForS3, $contents);
//Step 2: Return temporary URL from S3
$temporaryUrl = Storage::disk('s3')->temporaryUrl(
$filePathForS3,
Carbon::now()->addMinutes(10)
);
return $temporaryUrl;
}
}