fix: encode s3 metadata as base64 if needed

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2025-11-18 16:06:57 +01:00 committed by backportbot[bot]
parent b797d10465
commit d2b176fee8
2 changed files with 8 additions and 1 deletions

View file

@ -100,6 +100,9 @@ class S3 implements IObjectStore, IObjectStoreMultiPartUpload, IObjectStoreMetaD
$result = [];
foreach ($metadata as $key => $value) {
if (str_starts_with($key, 'x-amz-meta-')) {
if (str_starts_with($value, 'base64:')) {
$value = base64_decode(substr($value, 7));
}
$result[substr($key, strlen('x-amz-meta-'))] = $value;
}
}

View file

@ -82,7 +82,11 @@ trait S3ObjectTrait {
private function buildS3Metadata(array $metadata): array {
$result = [];
foreach ($metadata as $key => $value) {
$result['x-amz-meta-' . $key] = $value;
if (mb_check_encoding($value, 'ASCII')) {
$result['x-amz-meta-' . $key] = $value;
} else {
$result['x-amz-meta-' . $key] = 'base64:' . base64_encode($value);
}
}
return $result;
}