Hi I have 2 questions around programatically.
1) I need to save files to the DAM.
I can save jpg files using the code
public String ToDam(InputStream is, String fileName, javax.jcr.Session session, String damLocation, String fileType,String addOrRemove) {
try {
javax.jcr.Node node = session.getNode(damLocation);
javax.jcr.ValueFactory valueFactory = session.getValueFactory();
javax.jcr.Binary contentValue = valueFactory.createBinary(is);
javax.jcr.Node fileNode = node.addNode(fileName, "nt:file");
fileNode.addMixin("mix:referenceable");
javax.jcr.Node resNode = fileNode.addNode("jcr:content",
"nt:resource");
if (addOrRemove.equals("add")) {
resNode.setProperty("jcr:mimeType","image/jpeg");
resNode.setProperty("jcr:data", contentValue);
} else {
//TODO
}
Calendar lastModified = Calendar.getInstance();
lastModified.setTimeInMillis(lastModified.getTimeInMillis());
resNode.setProperty("jcr:lastModified", lastModified);
// Return the path to the document that was stored in CQ.
System.out.println(fileNode.getPath());
return fileNode.getPath();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
I have tried to save XML files using the above code with one change
resNode.setProperty("jcr:mimeType","XML");
The code runs, but i cannot locate the xml file in the CQ5 DAM http://localhost:4502/damadmin#/content/dam.
2) how does one delete files from a DAM node in Java.
Solved! Go to Solution.
Hi Clive,
Use the AssetManager API to work with DAM instead of directly dealing with the JCR Nodes.
1. To create a DAM resource
com.day.cq.dam.api.AssetManager assetMgr = resourceResolver.adaptTo(com.day.cq.dam.api.AssetManager.class);
assetMgr.createAsset(<attachmentPath>, <input stream>,<contentType>, true);
for XML files, contentype = 'application/xml'
2. To delete the DAM resource
com.adobe.granite.asset.api.AssetManager assetApiMgr = resourceResolver.adaptTo(com.adobe.granite.asset.api.AssetManager.class);
assetApiMgr.removeAsset(<asset path>);
Hi,
Add session.save() next to resNode.setProperty("jcr:lastModified", lastModified); line and to delete fileNode.remove().
Thanks.
Vikram
Views
Replies
Total Likes
Pls mention proper mimetype: resNode.setProperty("jcr:mimeType","application/xml");
Views
Replies
Total Likes
Here is a community article that talks about How To develop a Java client app that can upload multiple files to the AEM DAM. The use of the AssetManager is also in this article. The client developed is:
[img]MultipleSwingClient.png[/img]
Notice that each file that is uploaded is displayed in the client.
AEM applies different renditions to the digital assets:
[img]DAMRen.png[/img]
All assets are stored in the DAM:
[img]DamFiles.png[/img]
Here is the article:
http://helpx.adobe.com/experience-manager/using/multiple-digital-assets.html
Views
Replies
Total Likes
I think I would preffer to use the Asset class to do a lot of this stuff instead of manipulating the different nodes.
Or even the AssetHanlder http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/dam/api/handler/AssetHandler.html
/Ove
Views
Replies
Total Likes
Hi Clive,
Use the AssetManager API to work with DAM instead of directly dealing with the JCR Nodes.
1. To create a DAM resource
com.day.cq.dam.api.AssetManager assetMgr = resourceResolver.adaptTo(com.day.cq.dam.api.AssetManager.class);
assetMgr.createAsset(<attachmentPath>, <input stream>,<contentType>, true);
for XML files, contentype = 'application/xml'
2. To delete the DAM resource
com.adobe.granite.asset.api.AssetManager assetApiMgr = resourceResolver.adaptTo(com.adobe.granite.asset.api.AssetManager.class);
assetApiMgr.removeAsset(<asset path>);
Thank you
Views
Replies
Total Likes
For anyone reading this thread and wanting to perform this use case, see this AEM community article that talks about how to use the AssetManager API to programmatically upload files to the AEM DAM:
Uploading files to Adobe Experience Manager DAM using AssetManager API
Views
Replies
Total Likes
Following is the solution for getting data from DAM and writing the Data.
Views
Replies
Total Likes