Skip to content

Commit df863c0

Browse files
[9.x] Add S3 temporaryUploadUrl method to AwsS3V3Adapter (#45753)
* Add temporaryUploadUrl methdo to AwsS3V3Adapter * Add temporaryUploadUrl() to FilesystemAdapter * Update facade docblocks * Added aws s3 temporaryUploadUrl requiredHeaders option * Update facade docblocks * formatting --------- Co-authored-by: aneeskhan47 <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent f980dff commit df863c0

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

src/Illuminate/Filesystem/AwsS3V3Adapter.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,40 @@ public function temporaryUrl($path, $expiration, array $options = [])
9595
return (string) $uri;
9696
}
9797

98+
/**
99+
* Get a temporary upload URL for the file at the given path.
100+
*
101+
* @param string $path
102+
* @param \DateTimeInterface $expiration
103+
* @param array $options
104+
* @return array
105+
*/
106+
public function temporaryUploadUrl($path, $expiration, array $options = [])
107+
{
108+
$command = $this->client->getCommand('PutObject', array_merge([
109+
'Bucket' => $this->config['bucket'],
110+
'Key' => $this->prefixer->prefixPath($path),
111+
], $options));
112+
113+
$signedRequest = $this->client->createPresignedRequest(
114+
$command, $expiration, $options
115+
);
116+
117+
$uri = $signedRequest->getUri();
118+
119+
// If an explicit base URL has been set on the disk configuration then we will use
120+
// it as the base URL instead of the default path. This allows the developer to
121+
// have full control over the base path for this filesystem's generated URLs.
122+
if (isset($this->config['temporary_url'])) {
123+
$uri = $this->replaceBaseUrl($uri, $this->config['temporary_url']);
124+
}
125+
126+
return [
127+
'url' => (string) $uri,
128+
'headers' => $signedRequest->getHeaders(),
129+
];
130+
}
131+
98132
/**
99133
* Get the underlying S3 client.
100134
*

src/Illuminate/Filesystem/FilesystemAdapter.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,25 @@ public function temporaryUrl($path, $expiration, array $options = [])
733733
throw new RuntimeException('This driver does not support creating temporary URLs.');
734734
}
735735

736+
/**
737+
* Get a temporary upload URL for the file at the given path.
738+
*
739+
* @param string $path
740+
* @param \DateTimeInterface $expiration
741+
* @param array $options
742+
* @return array
743+
*
744+
* @throws \RuntimeException
745+
*/
746+
public function temporaryUploadUrl($path, $expiration, array $options = [])
747+
{
748+
if (method_exists($this->adapter, 'temporaryUploadUrl')) {
749+
return $this->adapter->temporaryUploadUrl($path, $expiration, $options);
750+
}
751+
752+
throw new RuntimeException('This driver does not support creating temporary upload URLs.');
753+
}
754+
736755
/**
737756
* Concatenate a path to a URL.
738757
*

src/Illuminate/Support/Facades/Storage.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
* @method static string url(string $path)
6060
* @method static bool providesTemporaryUrls()
6161
* @method static string temporaryUrl(string $path, \DateTimeInterface $expiration, array $options = [])
62+
* @method static array temporaryUploadUrl(string $path, \DateTimeInterface $expiration, array $options = [])
6263
* @method static \League\Flysystem\FilesystemOperator getDriver()
6364
* @method static \League\Flysystem\FilesystemAdapter getAdapter()
6465
* @method static array getConfig()

0 commit comments

Comments
 (0)