AnsweredAssumed Answered

Upload file from RestApi

Question asked by dharmendra.jaiswal on Jan 21, 2009
Latest reply on Sep 1, 2010 by groberts
Can anyone tell the example to use
POST /alfresco/service/sample/upload (http://wiki.alfresco.com/wiki/2.1_REST_API#File_Upload_Sample)

for uploading file into alfresco repository. I am using Alfresco Lab 3

How can I use this through HttpClient.


Code I m using is :
String URL = "http://localhost:8080/alfresco/service/sample/upload";
PostMethod post = new PostMethod(URL);
NameValuePair[] data = {new NameValuePair("filename", "C:/testFile.txt"),
              new NameValuePair("mimetype", "text/plain"),            
            new NameValuePair("containerId", "7018a7e3-d366-4389-84c6-bd79d793c270")};   //Company Homes' Id      
      
post.setRequestBody(data);
int statusCode1 = client.executeMethod(post);

The error I am getting is :
  "message" : "Failed to execute script '\/org\/alfresco\/upload.post.js (in classpath store file:D:\/alfresco\/tomcat\/webapps\/alfresco\/WEB-INF\/classes\/alfresco\/webscripts)': Failed to execute script '\/org\/alfresco\/upload.post.js (in classpath store file:D:\/alfresco\/tomcat\/webapps\/alfresco\/WEB-INF\/classes\/alfresco\/webscripts)': ReferenceError: \"formdata\" is not defined. (AlfrescoScript#21)", 
"org.mozilla.javascript.EcmaError: ReferenceError: \"formdata\" is not defined. (AlfrescoScript#21)"


I will be very thankful if anyone would give me example through sample code.

Regards.
DJ

Outcomes