Skip to content

Commit 9fcc293

Browse files
authored
Merge pull request #56515 from nextcloud/s3-meta-encode
Encode s3 metadata as base64 if needed
2 parents 93c7111 + a7d130c commit 9fcc293

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
480480
$metadata = [
481481
'mimetype' => $mimetype,
482482
'original-storage' => $this->getId(),
483-
'original-path' => rawurlencode($path),
483+
'original-path' => $path,
484484
];
485485
if ($size) {
486486
$metadata['size'] = $size;

lib/private/Files/ObjectStore/S3.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ private function parseS3Metadata(array $metadata): array {
100100
$result = [];
101101
foreach ($metadata as $key => $value) {
102102
if (str_starts_with($key, 'x-amz-meta-')) {
103+
if (str_starts_with($value, 'base64:')) {
104+
$value = base64_decode(substr($value, 7));
105+
}
103106
$result[substr($key, strlen('x-amz-meta-'))] = $value;
104107
}
105108
}

lib/private/Files/ObjectStore/S3ObjectTrait.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ public function readObject($urn) {
8282
private function buildS3Metadata(array $metadata): array {
8383
$result = [];
8484
foreach ($metadata as $key => $value) {
85-
$result['x-amz-meta-' . $key] = $value;
85+
if (mb_check_encoding($value, 'ASCII')) {
86+
$result['x-amz-meta-' . $key] = $value;
87+
} else {
88+
$result['x-amz-meta-' . $key] = 'base64:' . base64_encode($value);
89+
}
8690
}
8791
return $result;
8892
}

0 commit comments

Comments
 (0)