cancel
Showing results for 
Search instead for 
Did you mean: 

Missing content when create a document

lelejill
Champ in-the-making
Champ in-the-making
Hi,

I want to create a document by using: POST /alfresco/service/api/path/{store_type}/{store_id}/{id}/children

I can create it successfully in my space, but when I click on the document I create to see the content of it,

the following message comes up:

The node's content is missing:
   node: workspace://SpacesStore/42a0172c-32af-43c1-9045-9c511f3e5181
   reader: null 
Please contact your system administrator.

It seems there is sth wrong in my Atomentry xml to parse the content src.

Here is my java test code:
import java.io.File;
import java.io.FileInputStream;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.bouncycastle.util.encoders.Base64;

public class CreateDocPost {

   public static void main(String[] args) {

      try {
         String url ="http://localhost:8080/alfresco/service/api/path/workspace/SpacesStore/Company%20Home/Sites/children";
         String creds = "admin" + ":" + "admin";
         HttpClient httpClient = new HttpClient();
         PostMethod method = new PostMethod(url);
         method.setRequestHeader("Authorization", "Basic "
          + new String(Base64.encode(creds.getBytes())));

         String filePath ="D:/createdocpost.xml";
         String contentType = "application/atom+xml;type=entry";
         File createDoc = new File(filePath);
         method.setRequestHeader("name", createDoc.getName());
         method.setRequestHeader("Content-type", contentType);
         method.setRequestBody(new FileInputStream(createDoc));
         int status = httpClient.executeMethod(method);
         System.out.println("return code is: " + status + "\n\n" + " return body is :"
               + method.getResponseBodyAsString());

      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}


Here is my Atomentry sample xml:
<?xml version='1.0' encoding='utf-8'?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200901" xmlns:alf="http://www.alfresco.org">
<link rel="type" href="http://localhost:8080/alfresco/service/api/type/document'/>
<link rel="repository" href="http://localhost:8080/alfresco/service/api/repository'/>
<title>createDoc.txt</title>
<summary>create doc test Summary</summary>
<content type="text/plain" src="D:/joe.txt" />
<cmis:object>
<cmis:properties>
<cmis:propertyId cmis:name='ObjectTypeId'><cmis:value>document</cmis:value></cmis:propertyId>
</cmis:properties>
</cmis:object>
</entry>

Can anybody here help me out?

Thanks a lot

Xiaole
5 REPLIES 5

openpj
Elite Collaborator
Elite Collaborator
Usually with REST APIs, if you need to create a new content (node), you need to invoke a POST call.
To push and to update the content of a node you need to invoke a PUT call.

Have you tried to use directly the PUT method?

Hope this helps.

lelejill
Champ in-the-making
Champ in-the-making
Thanks OpenPj for your kindly reply Smiley Happy

I just change the atomEntry xml to put the document content into <content></content> tag with <![CDATA[ ]]>.

Seems it works well now.  Smiley Very Happy

sabeer
Champ in-the-making
Champ in-the-making
Hi,

I have just tried the same and file has been sucessfully uploaded but content is not updated.

Can you please help me to resolve this issue.

The below is the XML file.

******************************************************************
<?xml version='1.0' encoding='utf-8'?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200901" xmlns:alf="http://www.alfresco.org">
<link rel="type" href="http://localhost:8080/alfresco/service/api/type/document'/>
<link rel="repository" href="http://localhost:8080/alfresco/service/api/repository'/>
<title>demo.txt</title>
<summary>Demo document</summary>
<![CDATA[ <content type="text/plain" src="D:/demo.txt" /> ]]>
<cmisSmiley Surprisedbject>
<cmisSmiley Tongueroperties>
<cmisSmiley TongueropertyId cmis:name='ObjectTypeId'><cmis:value>document</cmis:value></cmisSmiley TongueropertyId>
</cmisSmiley Tongueroperties>
</cmisSmiley Surprisedbject>
</entry>
******************************************************************************

Regards
Sab

lelejill
Champ in-the-making
Champ in-the-making
Hi,

I have just tried the same and file has been sucessfully uploaded but content is not updated.

Can you please help me to resolve this issue.

The below is the XML file.

******************************************************************
<?xml version='1.0' encoding='utf-8'?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200901" xmlns:alf="http://www.alfresco.org">
<link rel="type" href="http://localhost:8080/alfresco/service/api/type/document'/>
<link rel="repository" href="http://localhost:8080/alfresco/service/api/repository'/>
<title>demo.txt</title>
<summary>Demo document</summary>
<![CDATA[ <content type="text/plain" src="D:/demo.txt" /> ]]>
<cmisSmiley Surprisedbject>
<cmisSmiley Tongueroperties>
<cmisSmiley TongueropertyId cmis:name='ObjectTypeId'><cmis:value>document</cmis:value></cmisSmiley TongueropertyId>
</cmisSmiley Tongueroperties>
</cmisSmiley Surprisedbject>
</entry>
******************************************************************************

Regards
Sab

Hi Sab,

Pls put the demo.txt file's content into <![CDATA[ ]]>, not the link from your local system.

eg:

if your demo.txt content is:
I am content of demo.txt.

then
<content><![CDATA[I am content of demo.txt]]></content>

Hope it helps Smiley Happy

walley
Champ in-the-making
Champ in-the-making
Hi Sab,

Pls put the demo.txt file's content into <![CDATA[ ]]>, not the link from your local system.

eg:

if your demo.txt content is:
I am content of demo.txt.

then
<content><![CDATA[I am content of demo.txt]]></content>

Hope it helps Smiley Happy

how to upload binary data?
Binary content in CDATA makes atom xml not well-formed.