Light, fluffy, and always free - The AWS Local Emulator alternative
fix(s3): persist x-amz-meta-* metadata from presigned POST uploads (#727)
Christine Nguyen692d665734d1
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.javaindex 470fedc894..8c94c22749 100644--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java@@ -1894,7 +1894,19 @@ public class S3Controller {objectContentType = "application/octet-stream";}- S3Object obj = s3Service.putObject(bucket, key, fileData, objectContentType, null);+ Map<String, String> metadata = new LinkedHashMap<>();+ for (Map.Entry<String, String> entry : fields.entrySet()) {+ String fieldName = entry.getKey().toLowerCase(Locale.ROOT);+ if (fieldName.startsWith("x-amz-meta-")) {+ String metaKey = fieldName.substring("x-amz-meta-".length());+ if (!metaKey.isBlank()) {+ metadata.put(metaKey, entry.getValue());+ }+ }+ }++ S3Object obj = s3Service.putObject(bucket, key, fileData, objectContentType,+ metadata.isEmpty() ? null : metadata);LOG.infov("Presigned POST upload: {0}/{1} ({2} bytes)", bucket, key, fileData.length);String xml = new XmlBuilder()diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3PresignedPostIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3PresignedPostIntegrationTest.javaindex 739ae1d69e..aa0b175e48 100644--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3PresignedPostIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3PresignedPostIntegrationTest.java@@ -476,6 +476,40 @@ class S3PresignedPostIntegrationTest {.header("ETag", notNullValue());}+ @Test+ @Order(97)+ void presignedPostPersistsUserMetadata() {+ String key = "uploads/with-metadata.txt";+ String fileContent = "metadata test";++ String policy = buildPolicy(BUCKET, key, "text/plain", 0, 10485760);+ String policyBase64 = Base64.getEncoder().encodeToString(policy.getBytes(StandardCharsets.UTF_8));++ given()+ .multiPart("key", key)+ .multiPart("Content-Type", "text/plain")+ .multiPart("policy", policyBase64)+ .multiPart("x-amz-algorithm", "AWS4-HMAC-SHA256")+ .multiPart("x-amz-credential", "AKIAIOSFODNN7EXAMPLE/20260330/us-east-1/s3/aws4_request")+ .multiPart("x-amz-date", AMZ_DATE_FORMAT.format(Instant.now()))+ .multiPart("x-amz-signature", "dummysignature")+ .multiPart("x-amz-meta-source", "camera")+ .multiPart("x-amz-meta-owner", "test-user")+ .multiPart("file", "with-metadata.txt", fileContent.getBytes(StandardCharsets.UTF_8), "text/plain")+ .when()+ .post("/" + BUCKET)+ .then()+ .statusCode(204);++ given()+ .when()+ .head("/" + BUCKET + "/" + key)+ .then()+ .statusCode(200)+ .header("x-amz-meta-source", equalTo("camera"))+ .header("x-amz-meta-owner", equalTo("test-user"));+ }+@Test@Order(100)void cleanupBucket() {@@ -487,6 +521,7 @@ class S3PresignedPostIntegrationTest {given().delete("/" + BUCKET + "/uploads/within-range.txt");given().delete("/" + BUCKET + "/uploads/prefix-test.txt");given().delete("/" + BUCKET + "/uploads/capital-p-ok.txt");+ given().delete("/" + BUCKET + "/uploads/with-metadata.txt");given().when()