Skip to content

Commit

Permalink
chore: Update S3FileSystem to support readable proxy URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Jun 26, 2024
1 parent 4d23c0d commit 1412991
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 16 additions & 2 deletions src/S3FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 1412991

Please sign in to comment.