cancel
Showing results for 
Search instead for 
Did you mean: 

Upload file / folder through webscript

lakshya
Champ in-the-making
Champ in-the-making
Hello,
I am able to create folder / document through REStful APIs.
But now facing the problem to upload the file from disk to repository.

For creating document I have written the following code :
URL = "http://localhost:8081/alfresco/service/api/path/workspace/SpacesStore/Company%20Home/children";
PostMethod method = new PostMethod(URL);
String contentType = "application/atom+xml;type=entry";
File upload = new File("testDoc.xml");
method.setRequestHeader("name", upload.getName());
method.setRequestHeader("Content-type", contentType);
method.setRequestBody(new FileInputStream(upload));
client.executeMethod(method);


testDoc.xml
<?xml version='1.0' encoding='utf-8'?>
        <entry xmlns='http://www.w3.org/2005/Atom' xmlns:cmis='http://www.cmis.org/2008/05'>
         <title>My Picts</title>
         <summary>My Picts – Summary</summary>       
         <cmisSmiley Surprisedbject>
          <cmisSmiley Tongueroperties>
           <cmisSmiley TongueropertyString cmis:name='ObjectTypeId'><cmis:value>document</cmis:value></cmisSmiley TongueropertyString>
          
          </cmisSmiley Tongueroperties>
         </cmisSmiley Surprisedbject>
       </entry>

How can I post the request to get the file from disk. XML should take the inputStream in this case.
How can I resolve this issue. Any pointer ??
2 REPLIES 2

lakshya
Champ in-the-making
Champ in-the-making
I have done some changes in xml.
I am setting the content in the form of byte array and passing  in method.setRequestBody().

I am getting the following error :
(in classpath store file:E:/alfresco/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts)': Wrapped org.apache.abdera.parser.ParseException: com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal character (NULL, unicode 0) encountered: not valid in any content

Isn't it possible to send the content as byte arrays through XML.

kocoubb
Champ in-the-making
Champ in-the-making
can you provide the webscript source for help.