cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve document content as byte array using UUID

narayana_giri
Champ in-the-making
Champ in-the-making
Hi,

Alfresco document was uploaded using web services RepositoryServiceSoapBindingStub and ContentServiceSoapBindingStub(SDK Samples API) and have complete URL of the document with UUID and file name - http://localhost:8080/alfresco/d/d/workspace/SpacesStore/e93b3b3f-774f-43fd-8c32-f3d44c0e570e/sample file.txt

Need to get the content of the document in byte array to scan it before displaying in the browser.

Can I read the alfresco document URL as any other URL to get the byte array as below:

URL url= new URL("http://localhost:8080/alfresco/d/d/workspace/SpacesStore/e93b3b3f-774f-43fd-8c32-f3d44c0e570e/build file.txt");
        BufferedReader in = new BufferedReader(
        new InputStreamReader(url.openStream()));

        String inputLine;
        while ((inputLine = in.readLine()) != null)
            System.out.println(inputLine);
        in.close();

If not possible to read as a URL, what is the simple Java or Web Service API(with links, documents or samples) to get byte array?

Alfresco version 4.2 and we are not using CMIS.

Thanks in advance for all your help.
3 REPLIES 3

marsbard
Champ in-the-making
Champ in-the-making
Have a look here: http://wiki.alfresco.com/wiki/NodeRef_cookbook#Reading_the_data_content_of_a_NodeRef_.28binary.29

It takes a nodeRef, not the UUID string, try the constructors of the NodeRef class to get the nodeRef http://dev.alfresco.com/resource/docs/java/datamodel/org/alfresco/service/cmr/repository/NodeRef.htm..., e.g.:

    NodeRef nodeRef = new NodeRef("workspace://SpacesStore/f1a5e908-80cb-4c6e-b919-cc80fe53b835");

Thanks for the reply.  Even though I searched in Alfresco forum and google it, unable to find reference to contentService.

How to get the reference to contentService in Alfresco 4.2

Again Thanks for all your support.

This tutorial shows how to create a content streaming webscript, including how to inject the contentService via Spring configuration (actually the serviceRegistry is injected, it contains references to the other services) : http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples#RenditionWebScript.java