Expand my Community achievements bar.

Upload assets programatically

Avatar

Level 9

I am uploading assets programatically to aem cloud using AssetManager createOrReplaceAsset method

image gets uploaded to AEM however it is taking 5-10 minutes to process the image, apply rendition and properties. I see a call to dynamic media server   https://<aem-auther-server>/adobe/dynamicmedia/deliver/dm-aid--0a0c72d9-d7e4-4f8f-80ae-8448bdaeddff/...   We dont have dynamic media install, why it is getting uploaded. How do I get the image instantaneously, are there any post processing required?

Here is my code

 

 

  JackrabbitValueFactory valueFactory = (JackrabbitValueFactory) session.getValueFactory();
    
            // Download the file with buffering
            InputStream inputStream = downloadFromSignedUrl(signedUrl);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
    
            // Detect MIME type and create binary
            String mimeType = getMimeType(bufferedInputStream);
            javax.jcr.Binary binary = valueFactory.createBinary(bufferedInputStream);
    
            // Use AssetManager to create or update the asset
            AssetManager assetManager = resolver.adaptTo(AssetManager.class);
            if (assetManager == null) {
                throw new IllegalStateException("Unable to adapt to AssetManager.");
            }
            
            // Create or update the asset without blocking rendition generation
            assetManager.createOrReplaceAsset(targetDamPath, binary, mimeType, false);
    
            LOGGER.info("Asset uploaded successfully to path: {}", targetDamPath);
            isUpload = true;
            session.save();

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Reply