Programatically working with the DAM
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.