diff --git a/config/cms.php b/config/cms.php index e0f58e236..bfe1930bb 100644 --- a/config/cms.php +++ b/config/cms.php @@ -252,14 +252,20 @@ return [ | folder - a folder prefix for storing all generated files inside. | path - the public path relative to the application base URL, | or you can specify a full URL path. + | + | Optionally, you can specify how long temporary URLs to protected files + | in cloud storage (ex. AWS, RackSpace) are valid for by setting + | temporaryUrlTTL to a value in seconds to define a validity period. This + | is only used for the 'uploads' config when using a supported cloud disk */ 'storage' => [ 'uploads' => [ - 'disk' => 'local', - 'folder' => 'uploads', - 'path' => '/storage/app/uploads', + 'disk' => 'local', + 'folder' => 'uploads', + 'path' => '/storage/app/uploads', + 'temporaryUrlTTL' => 3600, ], 'media' => [ diff --git a/modules/backend/controllers/Files.php b/modules/backend/controllers/Files.php index 220b26aab..525d8f5f8 100644 --- a/modules/backend/controllers/Files.php +++ b/modules/backend/controllers/Files.php @@ -2,6 +2,7 @@ use View; use Cache; +use Config; use Backend; use Response; use System\Models\File as FileModel; @@ -65,18 +66,18 @@ class Files extends Controller $url = null; $disk = $file->getDisk(); $adapter = $disk->getAdapter(); - if (is_a($adapter, 'League\Flysystem\Cached\CachedAdapter')) { + if ($adapter instanceof \League\Flysystem\Cached\CachedAdapter) { $adapter = $adapter->getAdapter(); } - if (is_a($adapter, 'League\Flysystem\AwsS3v3\AwsS3Adapter') || - is_a($adapter, 'League\Flysystem\Rackspace\RackspaceAdapter') || + if (($adapter instanceof \League\Flysystem\AwsS3v3\AwsS3Adapter) || + ($adapter instanceof \League\Flysystem\Rackspace\RackspaceAdapter) || method_exists($adapter, 'getTemporaryUrl') ) { if (empty($path)) { $path = $file->getDiskPath(); } - $expires = now()->addMinutes(60); + $expires = now()->addSeconds(Config::get('cms.storage.uploads.temporaryUrlTTL', 3600)); $url = Cache::remember('backend.file:' . $path, $expires, function () use ($disk, $path, $expires) { return $disk->temporaryUrl($path, $expires);