Skip to content

Commit 1412991

Browse files
committed
chore: Update S3FileSystem to support readable proxy URLs
1 parent 4d23c0d commit 1412991

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ In order to read more about upgrading and BC breaks have a look at the [UPGRADE
55

66
## 1.7.0
77

8-
+ allow the `acl` param to be null, since certain storage system throw an error if an unsupported header value is provided.
8+
+ Allow the `acl` param to be null, since certain storage system throw an error if an unsupported header value is provided.
9+
+ Added new `$readableProxyUrl` property.
910

1011
## 1.6.0 (12. April 2023)
1112

src/S3FileSystem.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ class S3FileSystem extends BaseFileSystemStorage
8080
*/
8181
public $maxAge = 2592000;
8282

83+
/**
84+
* 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.
85+
* @since 1.7.0
86+
*/
87+
public $readableProxyUrl;
88+
8389
/**
8490
* @inheritdoc
8591
*/
@@ -191,8 +197,16 @@ public function getS3Config()
191197
public function fileHttpPath($fileName)
192198
{
193199
if (!isset($this->_httpPaths[$fileName])) {
194-
Yii::debug('Get S3 object url: ' . $fileName, __METHOD__);
195-
$this->_httpPaths[$fileName] = $this->getClient()->getObjectUrl($this->bucket, $fileName);
200+
201+
$r = $this->getClient()->getObjectUrl($this->bucket, $fileName);
202+
203+
Yii::debug(['s3 request file: ' . $fileName, 's3 response: ' . $r], __METHOD__);
204+
205+
if ($this->readableProxyUrl) {
206+
$r = str_replace(["$this->endpoint/$this->bucket"], [$this->readableProxyUrl], $r);
207+
}
208+
209+
$this->_httpPaths[$fileName] = $r;
196210
}
197211

198212
return $this->_httpPaths[$fileName];

0 commit comments

Comments
 (0)