asset-share-commons
asset-share-commons copied to clipboard
Ability to Control Downloaded File's Name
When an asset rendition is requested for download, its is returned with a filename that's generated by the AssetRenditionParameters.buildFileName()
method, which appends the rendition name to the asset's name. Our client would prefer just the asset name (or maybe the title). There is no flexibility to allow for this.
*** Possible Solution ***
We can create a custom Sling Model for the Renditions component (which is what we're currently using to download a rendition). There, we could process the resulting download's title as we fit (using the title or the name or whatever other piece of metadata we may want to). That value could then be returned to the DOM and be made as part of the request that's sent to the AssetRenditionServlet
.
The AssetRenditionParameters.buildFileName()
method could then be ignored if a specific download title is provided as part of the request.
*** Current (roundabout) Solution ***
Currently, the only way I can think of resolving this requirement is to overlay the AssetRenditionServlet
entirely. Please let me know if there are other ways.
You can create your own DownloadArchiveNamer
OSGi service with a high service ranking (ex. 0
since OOTB is -1000
) (so it overrides the OOTB one) - this is used to create the archive file names.
Do note that this hook only works on AEM as a Cloud Service.
Here's the OOTB impl: https://github.com/adobe/asset-share-commons/blob/develop/core.cloud/src/main/java/com/adobe/aem/commons/assetshare/content/renditions/download/async/impl/ExpressionDownloadArchiveNamer.java
https://github.com/adobe/asset-share-commons/blob/develop/core.cloud/src/main/java/com/adobe/aem/commons/assetshare/content/renditions/download/async/DownloadArchiveNamer.java
Thanks @davidjgonzalez checking it
@davidjgonzalez will this apply also when we're using the Renditions
component to download an asset?
I could be mistaken but in looking at the code (and debugging), it seems as though Rendition downloads invoke the AssetRenditionServlet
which invokes
final AssetRenditionParameters parameters = new AssetRenditionParameters(request);
which then uses the buildFileName()
method to create the name.
That being said, I am doing this locally and you did say that DownloadArchiveNamer
implementations are cloud only so maybe the flow will be different on the cloud servers? Just wanted to make sure.
I think I found where this can be easily resolved. File ui.apps/src/main/content/jcr_root/apps/asset-share-commons/components/details/renditions/renditions.html
has a line where an anchor download value is being set:
download="${asset.title} - ${rendition.downloadFileName}"
This attribute value can be updated (or removed) to suit your needs.
I think I found where this can be easily resolved. File
ui.apps/src/main/content/jcr_root/apps/asset-share-commons/components/details/renditions/renditions.html
has a line where an anchor download value is being set:
download="${asset.title} - ${rendition.downloadFileName}"
This attribute value can be updated (or removed) to suit your needs.
Yes! This will change the filename when you download the rendition directly from the assets details page - but this does not affect the filename of files downloaded via the "download" functionality.