diff --git a/CHANGELOG.md b/CHANGELOG.md index 0af3eee..3ef084a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ In order to read more about upgrading and BC breaks have a look at the [UPGRADE ## 1.7.0 -+ allow the `acl` param to be null, since certain storage system throw an error if an unsupported header value is provided. ++ Allow the `acl` param to be null, since certain storage system throw an error if an unsupported header value is provided. ++ Added new `$readableProxyUrl` property. ## 1.6.0 (12. April 2023) diff --git a/src/S3FileSystem.php b/src/S3FileSystem.php index 1b45d73..4a66953 100644 --- a/src/S3FileSystem.php +++ b/src/S3FileSystem.php @@ -80,6 +80,12 @@ class S3FileSystem extends BaseFileSystemStorage */ public $maxAge = 2592000; + /** + * If defined, the endpoint and bucket name will be removed from the url and replaced with this value. This is can be helpful if migrating from an existing s3 url to another. + * @since 1.7.0 + */ + public $readableProxyUrl; + /** * @inheritdoc */ @@ -191,8 +197,16 @@ public function getS3Config() public function fileHttpPath($fileName) { if (!isset($this->_httpPaths[$fileName])) { - Yii::debug('Get S3 object url: ' . $fileName, __METHOD__); - $this->_httpPaths[$fileName] = $this->getClient()->getObjectUrl($this->bucket, $fileName); + + $r = $this->getClient()->getObjectUrl($this->bucket, $fileName); + + Yii::debug(['s3 request file: ' . $fileName, 's3 response: ' . $r], __METHOD__); + + if ($this->readableProxyUrl) { + $r = str_replace(["$this->endpoint/$this->bucket"], [$this->readableProxyUrl], $r); + } + + $this->_httpPaths[$fileName] = $r; } return $this->_httpPaths[$fileName];