cancel
Showing results for 
Search instead for 
Did you mean: 

Blob downloading problem with java automation client

murataht_
Champ in-the-making
Champ in-the-making

I am trying to download all the files (txt, html, pdf, doc, xls, ...) from nuxeo. To achieve this, I have found "Java automation client". (Hope I have made a good choice?)

My starting point is the example from the java automation client documentation: http://doc.nuxeo.com/display/public/NXDOC/Java+Automation+Client

  1. Getting all the docs:

         Documents docs = (Documents) session.newRequest("Document.Query").set(
     		"query", "SELECT * FROM Document WHERE ecm:primaryType=\'File\' " +
     		"OR ecm:primaryType=\'Note\'").execute();
    
  2. With an iteration, get every "doc" from "docs" and get its blob:

         Iterator<Document> it = docs.iterator();
     while (it.hasNext()){
     	Document doc = (Document)it.next();
             String path = doc.getPath();
         	path = URLEncoder.encode(path, "UTF-8");
     	Blob blob = (FileBlob) session.getFile(path);
     	try{
     		InputStream is = blob.getStream();
     		// do something with "is"
     	}catch(Exception e){
     		e.printStackTrace();
     	}
     }
    

But every time, I get the exception:

Exception in thread "main" java.lang.RuntimeException: Cannot execute {Authorization=Basic QWRtaW5pc3RyYXRvcjpBZG1pbmlzdHJhdG9y}
at org.nuxeo.ecm.automation.client.jaxrs.impl.HttpConnector.execute(HttpConnector.java:122)
at org.nuxeo.ecm.automation.client.jaxrs.spi.ConnectorHandler.execute(ConnectorHandler.java:30)
at org.nuxeo.ecm.automation.client.jaxrs.spi.DefaultSession.getFile(DefaultSession.java:127)
at Extract.main(Extract.java:79)
Caused by: java.lang.NullPointerException
at org.nuxeo.ecm.automation.client.RemoteException.extractInfo(RemoteException.java:61)
at org.nuxeo.ecm.automation.client.RemoteException.<init>(RemoteException.java:38)
at org.nuxeo.ecm.automation.client.jaxrs.impl.HttpConnector.execute(HttpConnector.java:145)
at org.nuxeo.ecm.automation.client.jaxrs.impl.HttpConnector.execute(HttpConnector.java:118)
... 3 more

I have spent already 2 days on this, and I am making little progress. Please help!!! thanks in advance!!!

4 REPLIES 4

Vladimir_Pasqui
Star Collaborator
Star Collaborator

Hi,

There are ways to download blobs with Nuxeo automation client:

// Retrieve document note with full schemas - or using Query operation with doc listing
    note = (Document) session.newRequest(DocumentService.FetchDocument).setHeader(
            Constants.HEADER_NX_SCHEMAS, "*").set("value",
            "/path/path").execute();

    PropertyList list = note.getProperties().getList("files:files");

    PropertyMap map = list.getMap(0).getMap("file");
    assertEquals(filename1, map.getString("name"));
    assertEquals("text/xml", map.getString("mime-type"));

    // get the data URL
    String path = map.getString("data");
    blob = (FileBlob) session.getFile(path);

    // the same for the second file
    map = list.getMap(1).getMap("file");
    assertEquals(filename2, map.getString("name"));
    assertEquals("text/xml", map.getString("mime-type"));

    // get the data URL
    path = map.getString("data");
    blob = (FileBlob) session.getFile(path);

You can have several informations on download blobs url pattern here: http://doc.nuxeo.com/display/NXDOC/Downloading+Files

Another way is to use "Blob.Get", "Blob.GetList", "Blob.GetAll" operations. Here an example:

// now test the GetDocumentBlobs operation on the note document
    blobs = (Blobs) session.newRequest(GetDocumentBlobs.ID).setInput(note).set(
            "xpath", "files:files").execute();

We're going to improve the way we can download blobs in general.

Thanks for your feedback.

thanks for your answer!!! i will let you about the results.

I tried the two methods. Bun in both methods, the "PropertyMap" I got was always null. So all I got was an exception, at the end.

@murataht this is not a forum, please don't post questions in the Answers section. Ask another question or update your original question or add a comment to it.

Getting started

Attention: Blogs & Forums are in READ-ONLY mode from Oct 9-19 as we transition to our new platform. Learn more.

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.