asset-share-commons icon indicating copy to clipboard operation
asset-share-commons copied to clipboard

Ability to Control Downloaded File's Name

Open DigiLiviu opened this issue 1 year ago • 5 comments

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.

DigiLiviu avatar Oct 31 '23 18:10 DigiLiviu

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

davidjgonzalez avatar Nov 02 '23 21:11 davidjgonzalez

Thanks @davidjgonzalez checking it

DigiLiviu avatar Nov 02 '23 21:11 DigiLiviu

@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.

DigiLiviu avatar Nov 03 '23 18:11 DigiLiviu

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.

dmaloon avatar Feb 29 '24 21:02 dmaloon

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.

davidjgonzalez avatar Mar 02 '24 04:03 davidjgonzalez