cancel
Showing results for 
Search instead for 
Did you mean: 

create new folder by web script :: POST /alfresco/s/api/site/folder/{site}/{container}

fahad
Champ in-the-making
Champ in-the-making
I want to create a new folder into my Site MySiteABC and its first folder is "REALISATIONS". Now I want to create a new folder inside REALISATIONS, but when I ran the following code I got 404 error;
{
    "status" :
  {
    "code" : 404,
    "name" : "Not Found",
    "description" : "Requested resource is not available."
  }, 
 
  "message" : "", 
  "exception" : "",
 
  "callstack" :
  [
       
  ],
 
  "server" : "Community v5.0.0 (r86473-b92) schema 8 006",
  "time" : "16 déc. 2014 17:23:06"
}

Can anyone tel me what I am doing wrong?? Do we require to create MultipartRequestEntity(parts, post.getParams())) for post here in this case??

I want to run the following script POST /alfresco/s/api/site/folder/{site}/{container}
   
public static void makeDirectory( String host, int port, String login, String password, String filepath) throws Exception {
      

      String site ="MySiteABC";
      
      String container= "REALISATIONS";
      
      
      
      String url1 = "http://159.84.130.209/alfresco/s/api/site/folder/%7B'+site+'%7D/%7B'+container+'%7D";

      System.out.println(" url is ==" + url1 );
      
      HttpClient client = new HttpClient();
      
      client.getState().setCredentials(
            new AuthScope(host, 80),

            new UsernamePasswordCredentials(login, password));
      

      PostMethod post = new PostMethod(url1);

      
   

      Part[] parts =
      { 

                  new StringPart( "name", "bernard34"),
                  new StringPart(  "type", "cm:folder")
      
                  
      };


       try
           {
       
              post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
              
   
              
            post.setDoAuthentication(true);//
            
            
   
             int status = client.executeMethod(post);

             System.out.println(post.getResponseBodyAsString());

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

any help would be encouraged.
1 REPLY 1

jpotts
World-Class Innovator
World-Class Innovator
Go checkout this project:
https://code.google.com/p/alfresco-api-java-examples/

Ignore the cloud/oauth stuff. Look at the createFolder() method. You'll see that using the OpenCMIS Java client from Apache Chemistry is a very simple way to create folders in Alfresco from Java code.

Jeff