From 5d82ae379189fcc1c3af4b20f8a0dcab5031fc8a Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Tue, 18 Jun 2024 16:10:48 +0200 Subject: [PATCH] Dynamic Media with OpenAPI: Download original binary when resolving media with download flag. (#56) --- changes.xml | 3 +++ .../ngdm/NextGenDynamicMediaRendition.java | 2 +- .../mediasource/ngdm/NextGenDynamicMediaTest.java | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/changes.xml b/changes.xml index 12855d07..59639f25 100644 --- a/changes.xml +++ b/changes.xml @@ -27,6 +27,9 @@ Dynamic Media with OpenAPI: Support Dynamic Media with OpenAPI also for local assets. + + Dynamic Media with OpenAPI: Download original binary when resolving media with download flag. + Dynamic Media with OpenAPI: Remove experimental URL parameters from default configuration. diff --git a/src/main/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMediaRendition.java b/src/main/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMediaRendition.java index 37e41478..ca499000 100644 --- a/src/main/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMediaRendition.java +++ b/src/main/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMediaRendition.java @@ -93,7 +93,7 @@ final class NextGenDynamicMediaRendition implements Rendition { this.fileExtension = FilenameUtils.getExtension(reference.getFileName()); } - if (isVectorImage() || !isImage()) { + if (isVectorImage() || !isImage() || mediaArgs.isDownload()) { // deliver as binary this.url = buildBinaryUrl(); } diff --git a/src/test/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMediaTest.java b/src/test/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMediaTest.java index f15a8fda..86623f83 100644 --- a/src/test/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMediaTest.java +++ b/src/test/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMediaTest.java @@ -226,6 +226,19 @@ void testPDFDownload() { assertEquals("https://repo1/adobe/assets/" + SAMPLE_ASSET_ID + "/original/as/myfile.pdf", rendition.getUrl()); } + @Test + void testImageDownload() { + Media media = mediaHandler.get(resource) + .args(new MediaArgs().download(true)) + .build(); + assertTrue(media.isValid()); + + Rendition rendition = media.getRendition(); + assertNotNull(rendition); + assertEquals(ContentType.JPEG, rendition.getMimeType()); + assertEquals("https://repo1/adobe/assets/" + SAMPLE_ASSET_ID + "/original/as/my-image.jpg", rendition.getUrl()); + } + private static void assertUrl(Media media, String urlParams, String extension) { assertEquals(buildUrl(urlParams, extension), media.getUrl()); }