Java clinet blob
I am writing a custom bulk importer by using client automation. I created new document but not able to load blobs.
below is the code.
import java.io.File;
import org.nuxeo.ecm.automation.client.Constants; import org.nuxeo.ecm.automation.client.Session; 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.model.FileBlob; import org.nuxeo.ecm.automation.client.model.PathRef; import org.nuxeo.ecm.automation.client.model.PropertyMap;
/**
*/
/**
@author kola * */ public class CreateDocument {
/**
@param args */ public static void main(String[] args) { HttpAutomationClient client = null; try{
client=new HttpAutomationClient("http://localhost:8080/nuxeo/site/automation"); Session session=client.getSession("Administrator", "Administrator"); System.out.println("Session : "+session); String strPath="/CCM"; PathRef pathref=new PathRef(strPath); System.out.println(" "+pathref.toString()); Document root = (Document) session.newRequest("Document.Fetch").set( "value", new PathRef(strPath)).execute(); session.newRequest("Document.Create").setInput(root).set("type", "File").set( "name", "myfile").set("properties", "dc:title=My File2").execute(); File file = new File("C:\\OBND_Comp2_Capability_Operation_Guide-2.1.pdf"); FileBlob fb = new FileBlob(file); fb.setMimeType("application/pdf"); session.newRequest("Blob.Attach").setHeader( Constants.HEADER_NX_VOIDOP, "true").setInput(fb) .set("document", "/myfile").execute(); // Get the file document where blob was attached Document doc = (Document) session.newRequest( "Document.Fetch").setHeader( Constants.HEADER_NX_SCHEMAS, "*").set("value", "/myfile").execute(); // get the file content property PropertyMap map = doc.getProperties().getMap("file:content"); // get the data URL String path = map.getString("data"); System.out.println(path); client.shutdown();
}catch(Exception ex){
ex.printStackTrace(); client.shutdown();
}
}
private static File getTheFileToUpload() {
File file=new File("<doc>C:\\OBND_Comp2_Capability_Operation_Guide-2.1.pdf</doc>"); return file;
}
}
Not able to preview the document. any insights appreciates.
sarathhi sarath will you please tell how did you resolve this issue ? Actually i am also searching for same kind of custom java code through which we can bulk import the files in to Nuxeo . Also tell me which external jars you added in the repositery ? Reply soon please. I have to implement this ASAP.