How to compare the size of the asset uploaded with the value from my custom OSGi configuration? | Community
Skip to main content
Level 2
May 17, 2022 6:13 PM UTC
Solved

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
SantoshSai
SantoshSaiAccepted solution
New Participant
May 17, 2022 7:45 PM UTC

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

8 replies

joerghoh
Employee
May 18, 2022 6:35 PM UTC

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.

Translate
SantoshSai
SantoshSaiAccepted solution
New Participant
May 17, 2022 7:45 PM UTC

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

Translate
Santosh Sai
ac6600Author
Level 2
May 17, 2022 8:32 PM UTC

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?

Translate
SantoshSai
New Participant
May 17, 2022 8:36 PM UTC

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

Translate
Santosh Sai