Skip to content

Commit

Permalink
Dynamic Media with OpenAPI: Support setting "Content Disposition Head…
Browse files Browse the repository at this point in the history
…er" to attachment for binary URLs (#60)
  • Loading branch information
stefanseifert authored Jul 4, 2024
1 parent 1bfca04 commit be5b378
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
3 changes: 3 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<action type="update" dev="sseifert" issue="59">
Dynamic Media with OpenAPI: Enable metadata service by default.
</action>
<action type="update" dev="sseifert" issue="60">
Dynamic Media with OpenAPI: Support setting "Content Disposition Header" to attachment for binary URLs
</action>
<action type="update" dev="sseifert" issue="53">
Improve trace logging: Make log messages involving value maps and resource/page objects more compact and better readable.
</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private boolean isRequestedDimensionLargerThanOriginal() {
* Build URL which points directly to the binary file.
*/
private String buildBinaryUrl() {
return new NextGenDynamicMediaBinaryUrlBuilder(context).build();
return new NextGenDynamicMediaBinaryUrlBuilder(context).build(mediaArgs.isContentDispositionAttachment());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public final class NextGenDynamicMediaBinaryUrlBuilder {

private final NextGenDynamicMediaContext context;

static final String PARAM_ATTACHMENT = "attachment";

/**
* @param context Context
*/
Expand All @@ -48,7 +50,7 @@ public NextGenDynamicMediaBinaryUrlBuilder(@NotNull NextGenDynamicMediaContext c
* Builds the URL for a binary.
* @return URL or null if invalid/not possible
*/
public @Nullable String build() {
public @Nullable String build(boolean contentDispositionAttachment) {

// get parameters from nextgen dynamic media config for URL parameters
String repositoryId;
Expand All @@ -73,6 +75,9 @@ public NextGenDynamicMediaBinaryUrlBuilder(@NotNull NextGenDynamicMediaContext c
url.append("https://")
.append(repositoryId)
.append(binaryDeliveryPath);
if (contentDispositionAttachment) {
url.append("?").append(PARAM_ATTACHMENT).append("=true");
}
return url.toString();
}

Expand Down
1 change: 0 additions & 1 deletion src/site/markdown/dynamic-media-openapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ The "wcm.io Dynamic Media with OpenAPI Metadata Service" allows to enable the As
* Same as with the Adobe AEM WCM Core Components, currently only a single remote AEM Asset instance is supported, which is configured centrally as described in [Dynamic Media with OpenAPI][aem-nextgen-dm]. The media handler uses the same convention for referencing remote assets (using strings starting with `/urn:aaid:aem:...`). This convention also does not support multiple remote AEM Asset instances, as it does not include a pointer to the Repository ID.
* If a component dialog is re-opened with a remote asset references and one of the Media Handler Granite UI widgets (e.g. pathfield), no thumbnail is displayed for the remote asset. But the reference is valid and works. The root cause is a bug/limitation in the underlying AEM pathfield component, which hopefully will be fixed soon by Adobe (SITES-19894).
* The Dynamic Media with OpenAPI remote asset picker currently ignores any folder structures for assets on the remote AEM Asset instance.
* The DM API currently does not support sending a "Content-Disposition: attachment" HTTP header for downloads. So, even if this is enforced by the Media Handler, it currently does not work for remote assets.


[aem-nextgen-dm]: https://experienceleague.adobe.com/docs/experience-manager-core-components/using/developing/next-gen-dm.html?lang=en
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void testAsset_SVG_Original() {
void testAsset_SVG_Original_ContentDisposition() {
Asset asset = createSampleAsset("/filetype/sample.svg", ContentType.SVG);
buildAssertMedia_ContentDisposition(asset, 100, 50,
"https://localrepo1/adobe/assets/urn:aaid:aem:12345678-abcd-abcd-abcd-abcd12345678/original/as/sample.svg",
"https://localrepo1/adobe/assets/urn:aaid:aem:12345678-abcd-abcd-abcd-abcd12345678/original/as/sample.svg?attachment=true",
ContentType.SVG);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void testAsset_SVG_Original() {
void testAsset_SVG_Original_ContentDisposition() {
Asset asset = createNextGenDynamicMediaReferenceAsAsset("sample.svg");
buildAssertMedia_ContentDisposition(asset, 0, 0,
"https://repo1/adobe/assets/" + SAMPLE_ASSET_ID + "/original/as/sample.svg",
"https://repo1/adobe/assets/" + SAMPLE_ASSET_ID + "/original/as/sample.svg?attachment=true",
ContentType.SVG);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@ void testBuild() {
NextGenDynamicMediaBinaryUrlBuilder underTest = getBuilder(new MediaArgs());

assertEquals("https://repo1/adobe/assets/urn:aaid:aem:12345678-abcd-abcd-abcd-abcd12345678/original/as/my-image.jpg",
underTest.build());
underTest.build(false));
}


@Test
void testBuild_ContentDispositionAttachment() {
NextGenDynamicMediaBinaryUrlBuilder underTest = getBuilder(new MediaArgs());

assertEquals("https://repo1/adobe/assets/urn:aaid:aem:12345678-abcd-abcd-abcd-abcd12345678/original/as/my-image.jpg?attachment=true",
underTest.build(true));
}

@SuppressWarnings("null")
Expand Down

0 comments on commit be5b378

Please sign in to comment.