Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Uploading File to AEM DAM

Avatar

Avatar
Validate 1
Level 1
vishalk87673574
Level 1

Likes

3 likes

Total Posts

5 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile

Avatar
Validate 1
Level 1
vishalk87673574
Level 1

Likes

3 likes

Total Posts

5 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile
vishalk87673574
Level 1

20-07-2017

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 A... "

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;

       }

View Entire Topic

Avatar

Avatar
Boost 5
Level 4
zeeshank1500736
Level 4

Likes

29 likes

Total Posts

103 posts

Correct Reply

33 solutions
Top badges earned
Boost 5
Boost 3
Boost 25
Boost 10
Boost 1
View profile

Avatar
Boost 5
Level 4
zeeshank1500736
Level 4

Likes

29 likes

Total Posts

103 posts

Correct Reply

33 solutions
Top badges earned
Boost 5
Boost 3
Boost 25
Boost 10
Boost 1
View profile
zeeshank1500736
Level 4

20-07-2017

your are already using annotation @Reference to inject the ResourceResolverFactory in your code.

@Reference

private static ResourceResolverFactory resolverFactory;

Create a write Service in AEM and put that service name in the "NAME of Your Write Service" in the code . for create service mapping follow the steps of the url Service Users in AEM | Adobe AEM Club

After creating the writeService and mapping with bundle.Below is your modified code in writeToClientLib.

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

       {

       try

       {

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

               //Please put your service name in place of NAME of Your Write Service

               param.put("NAME of Your Write Service" "writeService");

               ResourceResolver resolver = null;

          resolver = resolverFactory.getServiceResourceResolver(param);

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

com.day.cq.dam.api.AssetManager assetMgr = resolver.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;

       }