Skip to content

Commit

Permalink
Abstract the key to easier override (#156)
Browse files Browse the repository at this point in the history
* Abstract the key to easier override

Spoke with Joe about this idea via email.

We need the ability to change the key in our app. Specifically because we a prefix in `config/filesystems.php` and use the same bucket across multiple staging environments.

Per the discussion we would need to override the controller and customize it ourselves.

It would be helpful if the key was abstracted so we didn't have to duplicate the entire logic in `store`

* Update SignedStorageUrlController.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
lonnylot and taylorotwell authored Jul 24, 2023
1 parent 7a42ef1 commit 36886e9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Http/Controllers/SignedStorageUrlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function store(Request $request)
$expiresAfter = config('vapor.signed_storage_url_expires_after', 5);

$signedRequest = $client->createPresignedRequest(
$this->createCommand($request, $client, $bucket, $key = ('tmp/'.$uuid)),
$this->createCommand($request, $client, $bucket, $key = $this->getKey($uuid)),
sprintf('+%s minutes', $expiresAfter)
);

Expand Down Expand Up @@ -141,6 +141,17 @@ protected function storageClient()
return new S3Client($config);
}

/**
* Get key for the given UUID.
*
* @param string $uuid
* @return string
*/
protected function getKey(string $uuid)
{
return 'tmp/'.$uuid;
}

/**
* Get the default visibility for uploads.
*
Expand Down

0 comments on commit 36886e9

Please sign in to comment.