Uploading File to AEM DAM | Community
Skip to main content
Level 2
July 20, 2017
Solved

Uploading File to AEM DAM

  • July 20, 2017
  • 17 replies
  • 11389 views

I am working on a Project to upload files to AEM DAM through Java API. So was going through this tutorial to upload files in DAM.

"Adobe Experience Manager Help | Uploading files to Adobe Experience Manager DAM using AssetManager API "

But I am not able to get this code check as I am getting “Null Pointer Exception” @ ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);

Pasting the code as well which I am writing, just to let you know AEM is running on a different server and I am trying to connect to that server from my local, Idea is to deploy it as a Rest API in a different server from AEM.

Thanks in advance any help will be appreciated.

@Reference

       private static ResourceResolverFactory resolverFactory;

       public static void main(String[] args) {

//InputStream is =null;

try{

File initialFile = new File("C:/Users/502719757/Desktop/DOC0928611r8VCT_750HD_RevDis.pdf");

InputStream targetStream = new FileInputStream(initialFile);

String fileName = "DOC0928611r8VCT_750HD_RevDis.pdf";

String path = "http://uswaupmcvms01l.am.health.ge.com:8001/content/dam/travel";

String mimetype= null;

writeToClientLib(targetStream,fileName,path,mimetype);

}

catch(Exception e){

}

       }

      

       //

       private static String writeToClientLib(InputStream is, String fileName, String path, String mimetype)

       {

       try

       {

//Inject a ResourceResolver

ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);

//Use AssetManager to place the file into the AEM DAM

com.day.cq.dam.api.AssetManager assetMgr = resourceResolver.adaptTo(com.day.cq.dam.api.AssetManager.class);

String newFile = path+fileName ;

assetMgr.createAsset(newFile, is, mimetype, true);

// Return the path to the document that was stored in CRX.

return newFile;

       }

       catch(Exception e)

       {

e.printStackTrace();

System.out.println(e);

       }

       return null;

       }

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 zeeshanKhan0786

Hi Vishal,

ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null); has been diprecated .

You can get service mapping go through below will help

Service Users in AEM | Adobe AEM Club

AEM6: ResourceResolver access in services - WE ARE INSIDE

17 replies

smacdonald2008
Level 10
July 21, 2017

This is for AEM Versions Experience Manager 5.5, 5.6, 6.0, 6.1. In the correct version - you need to use a System user and the Sling Mapping Service. TO learn how to do this -- see this article:

Scott's Digital Community: Querying Adobe Experience Manager 6 data using the Sling getServiceResourceResolver method

smacdonald2008
Level 10
July 21, 2017

We will update that article to show use of this in AEM 6.3.

Level 2
July 21, 2017

Thanks smacdonald2008 for your suggestions.

Just wanted to be sure I am following the correct approach.

I am deploying an application(may be Rest API) on a different server and AEM is running on a different server.

With this API I want to upload some files to AEM repository(DAM), would this be the efficient method or is there any other way of doing this?

smacdonald2008
Level 10
July 21, 2017

You can use Restful method to upload an asset to AEM - see:

Scott's Digital Community: Creating Java Swing applications that post files to AEM ClientLibs folders

This uses an sample Java Swing client to send a POST to a sling servlet - the only thing you need to change is use System user and Sling Mapping as opposed to the Admin login call.

Kyaw_Zwa_Myint
Level 2
September 22, 2017

Support

Kyaw_Zwa_Myint
Level 2
September 22, 2017

Kyaw_Zwa_Myint
Level 2
September 22, 2017

Support