Dan Brown

Added check for s3 bucket name to choose shortest url

...@@ -259,9 +259,15 @@ class ImageService ...@@ -259,9 +259,15 @@ class ImageService
259 $storageUrl = config('filesystems.url'); 259 $storageUrl = config('filesystems.url');
260 260
261 // Get the standard public s3 url if s3 is set as storage type 261 // Get the standard public s3 url if s3 is set as storage type
262 + // Uses the nice, short URL if bucket name has no periods in otherwise the longer
263 + // region-based url will be used to prevent http issues.
262 if ($storageUrl == false && config('filesystems.default') === 's3') { 264 if ($storageUrl == false && config('filesystems.default') === 's3') {
263 $storageDetails = config('filesystems.disks.s3'); 265 $storageDetails = config('filesystems.disks.s3');
264 - $storageUrl = 'https://' . $storageDetails['bucket'] . '.s3.amazonaws.com'; 266 + if (strpos($storageDetails['bucket'], '.') === false) {
267 + $storageUrl = 'https://' . $storageDetails['bucket'] . '.s3.amazonaws.com';
268 + } else {
269 + $storageUrl = 'https://s3-' . $storageDetails['region'] . '.amazonaws.com/' . $storageDetails['bucket'];
270 + }
265 } 271 }
266 272
267 $this->storageUrl = $storageUrl; 273 $this->storageUrl = $storageUrl;
......