Expand my Community achievements bar.

SOLVED

Uploading image from Tomcat to Dam

Avatar

Level 3

Hi I am trying to upload an image from tomcat to AEM 6.3 DAM. But seems createAsset method of package com.adobe.granite.asset.api.AssetManager is not working as expected. Could anyone please help me as I am able to upload the image if I am using method from com.day.cq.dam.api.AssetManager pthis package.

My code below

HttpURLConnection con = null;

AssetManager assetManager = resolver.adaptTo(AssetManager.class);

  URL urlObj = new URL(assetUrl);

  con = (HttpURLConnection) urlObj.openConnection();

  con.setRequestMethod("GET");

  InputStream is = con.getInputStream();

  Asset asset = assetManager.createAsset(path);

  Map<String, Object> map = new HashMap<>();

  map.put(RenditionHandler.PROPERTY_RENDITION_MIME_TYPE, "image/jpeg");

  asset.setRendition("original", is, map);

Method Call :-

.downloadAndSaveAsset(resolver, "http://localhost:8080/images/new1.jpg",

  "/content/dam/new-folder/new1.jpg");

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

I don't think it's a bug in the new API.

The Granite AssetManager doesn't seem to be related to the CQ DAM AssetManager API (besides the name and the similarity of some methods). The most important aspect is that the CQ DAM AssetManager is not deprecated and therefor a fully supported API. I would stick with it and check how the Granite AssetManager API evolves in the next versions of AEM.

Jörg

View solution in original post

8 Replies

Avatar

Community Advisor

What exactly are you trying to achieve here ? I do see the URL you mentioned here is your localhost. Can you first check if the connection is established proper;y ? are you getting valid connection objects and if your inputstream has valid data ?

     If all are fine and if you are getting any error , can you paste your error log to check what exactly is wrong here ?

Avatar

Level 10

To upload a image from outside of AEM - write a servlet that uses the Asset Manager API and then post the file to the servlet.

Scott's Digital Community: Uploading files to Adobe Experience Manager DAM using AssetManager API

See the Java Servlet code that uses Asset Manager API.

Avatar

Level 3

Hi Veena,

I am trying to save an image from Tomcat server to AEM DAM. Connection is getting established even image is getting uploaded if I use the method create Assest from the Old API com.day.cq.dam.api.AssetManager.

But when I am using the new API com.adobe.granite.asset.api.AssetManager CreateAssest method which accepts only one parameter my image is not getting uploaded. Even I am not getting any error in error logs also

Avatar

Level 3

Hi Scott,

I am able to upload the image by using old API  com.day.cq.dam.api.AssetManager create assest method. My concern is I am not able to do the same if I am using the createAssest method of new API com.adobe.granite.asset.api.AssetManager.

Avatar

Community Advisor

Can you send the error log you are getting ?

Avatar

Level 3

I am not getting any error in logs. It is succesfully printing the next line. Even if I try retrieving the same assest from Resource by giving the path I am able to get it. But I could not see that image in CRX

Avatar

Level 10

I would revert to the API that works and log a bug against the new API.

Avatar

Correct answer by
Employee Advisor

I don't think it's a bug in the new API.

The Granite AssetManager doesn't seem to be related to the CQ DAM AssetManager API (besides the name and the similarity of some methods). The most important aspect is that the CQ DAM AssetManager is not deprecated and therefor a fully supported API. I would stick with it and check how the Granite AssetManager API evolves in the next versions of AEM.

Jörg