How to compare the size of the asset uploaded with the value from my custom OSGi configuration? | Adobe Higher Education
Skip to main content
Level 2
May 17, 2022
Répondu

How to compare the size of the asset uploaded with the value from my custom OSGi configuration?

I have created an OSGi Config as follows:

I am reading the values like:

Now, what I want to do is I want to compare the size of the asset file uploaded with assetSize value [from OSGi] when activated = true. And if size of asset file > assetSize, then the asset won't get uploaded to DAM and will show a error message.

Ce sujet a été fermé aux réponses.
Meilleure réponse par SantoshSai

Hi @ac6600 

AssetDetails asset = new AssetDetails(assetResource);
asset.getOriginal.getsize();
if(asset.getSize() < assetSize) {
     // Do Something
}


Asset API: https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/adobe/granite/asset/api/Asset.html

Rendition API: https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/dam/api/Rendition.html

Hope that helps you!

Regards,

Santosh

2 commentaires

SantoshSai
Community Advisor
SantoshSaiCommunity AdvisorRéponse
Community Advisor
May 17, 2022

Hi @ac6600 

AssetDetails asset = new AssetDetails(assetResource);
asset.getOriginal.getsize();
if(asset.getSize() < assetSize) {
     // Do Something
}


Asset API: https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/adobe/granite/asset/api/Asset.html

Rendition API: https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/dam/api/Rendition.html

Hope that helps you!

Regards,

Santosh

Santosh Sai
ac6600Auteur
Level 2
May 17, 2022

Hi @santoshsai , thanks for the solve. One more thing(maybe a dumb question), where shall I write this piece of code. Like will this be part of servlet or shall I write this within the OSGi config or anything else?

SantoshSai
Community Advisor
Community Advisor
May 17, 2022

Hi @ac6600 

I wound't do it in servlet, However, you can implement it in same class where you are reading configuration values by creating separate method or in separate service component.

Hope that helps!

Regards,
Santosh

Santosh Sai
joerghoh
Adobe Employee
Adobe Employee
May 18, 2022

The problem is that you need to hook into the asset upload process itself somehow. At best in a way, that terminates the request as soon as it crosses the configured value in the request body's size.

 

In AEM 6.x I don't think that there is a public API for it, and in AEM CS it is not possible at all, because the upload itself does not happen via the JVM at all.

The best way is either to restrict the frontend to prevent selecting larger assets to handle the cases when they are already uploaded.