Uploading image from Tomcat to Dam | Community
Skip to main content
Level 2
December 15, 2017
Solved

Uploading image from Tomcat to Dam

  • December 15, 2017
  • 8 replies
  • 3183 views

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");

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joerghoh

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

8 replies

VeenaVikraman
Community Advisor
Community Advisor
December 15, 2017

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 ?

smacdonald2008
Level 10
December 15, 2017

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.

Level 2
December 18, 2017

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

Level 2
December 18, 2017

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.

VeenaVikraman
Community Advisor
Community Advisor
December 18, 2017

Can you send the error log you are getting ?

Level 2
December 19, 2017

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

smacdonald2008
Level 10
December 19, 2017

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

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
December 19, 2017

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