Skip to content

Commit

Permalink
Use new method in Laravel 9 for generating temporary S3 URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
frasmage committed Mar 22, 2022
1 parent 5284e64 commit d1125eb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/UrlGenerators/S3UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

namespace Plank\Mediable\UrlGenerators;

use Aws\S3\S3Client;
use Aws\S3\S3ClientInterface;
use Illuminate\Contracts\Config\Repository as Config;
use Illuminate\Contracts\Filesystem\Cloud;
use Illuminate\Filesystem\FilesystemManager;
use Illuminate\Support\Arr;
use Plank\Mediable\Helpers\File;

class S3UrlGenerator extends BaseUrlGenerator implements TemporaryUrlGeneratorInterface
Expand Down Expand Up @@ -47,8 +50,16 @@ public function getUrl(): string

public function getTemporaryUrl(\DateTimeInterface $expiry): string
{
$filesystem = $this->filesystem->disk($this->media->disk);

// Laravel 9+ / Flysystem 2+
if (method_exists($filesystem, 'temporaryUrl')) {
return $filesystem->temporaryUrl($this->media->getDiskPath(), $expiry);
}

// Earlier versions
$root = config("filesystems.disks.{$this->media->disk}.root", '');
$adapter = $this->filesystem->disk($this->media->disk)->getDriver()->getAdapter();
$adapter = $filesystem->getDriver()->getAdapter();
$command = $adapter->getClient()->getCommand(
'GetObject',
[
Expand Down

0 comments on commit d1125eb

Please sign in to comment.