How to Add Document Deletion feature REST exposition?

May i know the client code for delete a particular file from remote server(nuxeo)through REST API.

Please share your views with me!

Thanks

0 votes

1 answers

3590 views

ANSWER

This question comes from http://doc.nuxeo.com/x/vwIz
03/14/2012



First a little precision about your question. When you talk about File in Nuxeo we talk about binaries (Word file, LibreOffice file, …). The object that stores metadata and optionally file(s) is called Document or Nuxeo Document.

So I think that you would like to remove a Nuxeo Document through a HTTP Call.

You have at least 3 possibilities to do that with Nuxeo.


First through the old Nuxeo REST API:

You just have to do the following GET request:

http://yourServer:port/nuxeo/restAPI/default/c800c2f2-b834-4751-b362-db821d5ce30b/deleteDocumentRestlet

where c800c2f2-b834-4751-b362-db821d5ce30b is the id of your document


Secondly through the Automation REST API and Automation client library:

import org.nuxeo.ecm.automation.client.adapters.DocumentService;
import org.nuxeo.ecm.automation.client.jaxrs.impl.HttpAutomationClient;
import org.nuxeo.ecm.automation.client.model.Document;
import org.nuxeo.ecm.automation.client.Session;

public static void main(String[] args) throws Exception {
    HttpAutomationClient client = new HttpAutomationClient(
           "http://yourServer:port/nuxeo/site/automation");

    Session session = client.getSession("Administrator", "Administrator");
    // Fetch the document
    Document doc = (Document) session.newRequest(DocumentService.FetchDocument).set(
                "value", "/path/of/your/document").execute();
    // Delete it
    session.newRequest(DocumentService.DeleteDocument).setInput(doc).execute();

    client.shutdown();
}

You can put the path (“/path/of/your/document”) like I did here or the id if you want.


Or you create an operation that fetch the document according a given parameter “docRef” and remove it:

  • Fetch > Document (value = @{Context[“docRef”]})
  • Document > Delete

And the call with curl, for instance, will be like that:

curl -H 'Content-Type:application/json+nxrequest' -X POST 
  -d '{"params":{"docRef":"/path/of/your/document"},"context":{}}' 
  -u Administrator:Administrator http://localhost:8080/nuxeo/site/automation/NameOfYouOperation
3 votes