Skip to content

Commit 4863802

Browse files
feat: add prefix-without-leading-slash to s3 URLs
In previous versions, when a prefix is set in flysystem+s3 urls, it preservers a leading slash as first character. In S3 this is not desirable, since it will add a directory with "/" an URLs will result in double slash https://bucket.s3-domain//prefix/... Since this cannot be fixed without getting a BC, we add a parameter to get a correct behavior.
1 parent 4281a96 commit 4863802

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Filesystem/Flysystem/AdapterFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private static function createS3Adapter(array $parsed): FilesystemAdapter // @ph
176176
'accessKeySecret' => $parsed['pass'] ?? null,
177177
]),
178178
$parsed['host'] ?? throw new \InvalidArgumentException('A bucket must be set as the host.'), // bucket
179-
$parsed['path'] ?? '', // prefix
179+
isset($parse['query']['prefix-without-leading-slash']) ? preg_replace('/^\//', '', $parsed['path'] ?? '') : ($parsed['path'] ?? ''), // prefix
180180
);
181181
}
182182

@@ -191,7 +191,7 @@ private static function createS3Adapter(array $parsed): FilesystemAdapter // @ph
191191
'version' => $parsed['query']['version'] ?? 'latest',
192192
]),
193193
$parsed['host'] ?? throw new \InvalidArgumentException('A bucket must be set as the host.'), // bucket
194-
$parsed['path'] ?? '', // prefix
194+
isset($parsed['query']['prefix-without-leading-slash']) ? preg_replace('/^\//', '', $parsed['path'] ?? '') : ($parsed['path'] ?? ''), // prefix
195195
);
196196
}
197197

0 commit comments

Comments
 (0)