Skip to content

Commit 263d990

Browse files
authored
Merge pull request #45 from uchajk/master
feat: add ability to use s3 storage
2 parents 8bf7f9d + 1cfb840 commit 263d990

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/Jobs/DataTableExportJob.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Contracts\Support\Arrayable;
1212
use Illuminate\Database\Eloquent\Model;
1313
use Illuminate\Foundation\Bus\Dispatchable;
14+
use Illuminate\Http\File;
1415
use Illuminate\Queue\InteractsWithQueue;
1516
use Illuminate\Queue\SerializesModels;
1617
use Illuminate\Support\Arr;
@@ -179,6 +180,10 @@ public function handle()
179180
}
180181

181182
$writer->close();
183+
184+
if($this->getS3Disk()) {
185+
Storage::disk($this->getS3Disk())->putFileAs('', (new File($path)), $filename);
186+
}
182187
}
183188

184189
/**
@@ -189,6 +194,14 @@ protected function getDisk(): string
189194
return strval(config('datatables-export.disk', 'local'));
190195
}
191196

197+
/**
198+
* @return string
199+
*/
200+
protected function getS3Disk(): string
201+
{
202+
return strval(config('datatables-export.s3_disk', ''));
203+
}
204+
192205
/**
193206
* @param \Yajra\DataTables\Services\DataTable $dataTable
194207
* @return \Illuminate\Support\Collection<array-key, Column>

src/Livewire/ExportButtonComponent.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ public function updateExportProgress(): ?StreamedResponse
7474

7575
public function downloadExport(): StreamedResponse
7676
{
77-
return Storage::disk($this->getDisk())
78-
->download($this->batchJobId.'.'.$this->getType(), $this->getFilename());
77+
if($this->getS3Disk()) {
78+
return Storage::disk($this->getS3Disk())->download($this->batchJobId.'.'.$this->getType(), $this->getFilename());
79+
}
80+
return Storage::disk($this->getDisk())->download($this->batchJobId.'.'.$this->getType(), $this->getFilename());
7981
}
8082

8183
protected function getType(): string
@@ -110,4 +112,12 @@ protected function getDisk(): string
110112

111113
return $disk;
112114
}
115+
116+
protected function getS3Disk(): string
117+
{
118+
/** @var string $disk */
119+
$disk = config('datatables-export.s3_disk', '');
120+
121+
return $disk;
122+
}
113123
}

src/config/datatables-export.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@
3838
*/
3939
'disk' => 'local',
4040

41+
/*
42+
|--------------------------------------------------------------------------
43+
| Use S3 for final file destination
44+
|--------------------------------------------------------------------------
45+
|
46+
| After generating the file locally, it can be uploaded to s3.
47+
|
48+
*/
49+
's3_disk' => '',
50+
4151
/*
4252
|--------------------------------------------------------------------------
4353
| Default Date Format

0 commit comments

Comments
 (0)