Skip to content

Commit

Permalink
Dynamic Media with OpenAPI: Download original binary when resolving m…
Browse files Browse the repository at this point in the history
…edia with download flag. (#56)
  • Loading branch information
stefanseifert authored Jun 18, 2024
1 parent ae75d70 commit 5d82ae3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<action type="add" dev="sseifert" issue="52">
Dynamic Media with OpenAPI: Support Dynamic Media with OpenAPI also for local assets.
</action>
<action type="update" dev="sseifert" issue="56">
Dynamic Media with OpenAPI: Download original binary when resolving media with download flag.
</action>
<action type="update" dev="sseifert" issue="54">
Dynamic Media with OpenAPI: Remove experimental URL parameters from default configuration.
</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 5d82ae3

Please sign in to comment.