Panda
Panda

Reputation: 83

Can we Delete uploaded files from dam

I need to delete uploaded files from DAM Asset programmatically. Can we delete particular file node from DAM?

Path:- /content/dam/nextgen/Ehub-POD/....

Inside Ehub-POD , I'm creating a folder and upload files. In jsp page I'll select particular file and need to delete the file from dam as well as from the jsp.

Upvotes: 0

Views: 1501

Answers (2)

Imran Saeed
Imran Saeed

Reputation: 3444

Another way to do it via CURL:

You can do a CURL DELETE request to the image path to remove it. Also, you can find all references to an image using CURL via following command:

http://localhost:4502/bin/wcm/references.json?path=/content/dam/nextgen/Ehub-POD/test-image.png

This will give you references of all the places where this image is used (except CSS or JS).

Upvotes: 0

dzenisiy
dzenisiy

Reputation: 865

Let's Imagine we have the following image in dam:

/content/dam/nextgen/Ehub-POD/image1.jpg

To remove it use jcr Session:

session.removeItem("/content/dam/nextgen/Ehub-POD/image1.jpg")
if (session.hasPendingChanges()) {
    session.save();        
}

Image from dam will be removed, now you need to run query to find out where image was used and delete fileReference property:

Workspace workspace = session.getWorkspace();
QueryManager qm = workspace.getQueryManager();
Query query = qm.createQuery("/jcr:root/content/websitename/*[@fileReference='/content/dam/nextgen/Ehub-POD/image1.jpg']", Query.XPATH);
QueryResult queryResult = query.execute();
result = queryResult.getNodes();
while (result.hasNext()) {
    Node node = result.nextNode();
    node.getProperty("fileReference").remove();
}

or you can delete all info about image, received node store info about cropping, fileReference and etc:

while (result.hasNext()) {
    Node node = result.nextNode();
    node.remove();
}

and don't forget to save your repository changes

if (session.hasPendingChanges()) {
    session.save();        
}

Upvotes: 0

Related Questions