Uploading File to AEM DAM
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.
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;
}