Ma Kro
Ma Kro

Reputation: 1242

AEM - How to upload image programmatically

I'm trying to upload an image programmatically in aem. It is a simple jpeg, or png. I tried to create node by hand and I also tried using AssetManager.createAsset.

Image was created but workflows has failed. I get stacktraces in AEM logs (of course those are not full logs, just headers):

com.day.cq.dam.commons.handler.StandardImageHandler getImage: error while reading image at path
com.day.cq.dam.commons.handler.StandardImageHandler failed to extract image using Layer will try the fallback
javax.imageio.IIOException: No decoder available to load the image
com.day.cq.dam.core.impl.gfx.CommonsGfxRenderer gfx: cannot get image for asset
com.day.cq.dam.commons.handler.StandardImageHandler getImage: error while reading image at path [/content/dam/path/to/image/original]: 
org.apache.commons.imaging.ImageReadException: Can't parse this format.

Any ideas why this is happening? Workflows throws errors, thumbnails are not created, metadata are not extracted.

Upvotes: 2

Views: 6337

Answers (2)

dzenisiy
dzenisiy

Reputation: 865

Asset asset = assetManager.createAsset(damPath, in, dataMimeType, false);

Are your's dataMimeType correct? For example, It should be "image/jpeg"

Also may be useful : https://helpx.adobe.com/experience-manager/using/uploading-files-aem1.html

Upvotes: 2

Bertrand Delacretaz
Bertrand Delacretaz

Reputation: 6100

You are probably missing the jcr:mimeType property on the image node. Best might be to upload an image via WebDAV and check the node structure that this creates. Reproducing that structure programatically should work.

Upvotes: 2

Related Questions