cancel
Showing results for 
Search instead for 
Did you mean: 

Getting 404 Response code while uploading file

dipakj
Champ in-the-making
Champ in-the-making
Hi ,

I am new in using REST API and Alfresco.
I am trying to upload file in Alfresco using Rest API  but i m getting 404  response code.
I am using REST API.

url using  : http://localhost:8080/alfresco/service/sample/upload

Please help me to reolve this problem.
2 REPLIES 2

steffen
Champ in-the-making
Champ in-the-making
Hi,

is this a custom web script? looks like there is no service at the url you requested (404 - not found)…

the url for the standard (none cmis) rest upload service is:

http://localhost:8080alfresco/service/api/upload

you can find an overview of all currently installed web scripts at:

http://localhost:9090/alfresco/service/index/all

steffen

dipakj
Champ in-the-making
Champ in-the-making
Hi ,

Thanks for help.

This is not custom webscript .I got this url from Alfresco site

url is: http://localhost:8080/alfresco/service/sample/upload.

and also i have tried another url.This webscript is installed in Alfresco.
http://localhost:8080/alfresco/service/api/upload
I got two status code 401 when I try from my code. and 405 when I paste above url in browser.



private void authenticateUser() {
      client = new HttpClient();
      // Add authentication preferences as Basic
      List authPrefs = new ArrayList(2);
      authPrefs.add(AuthPolicy.BASIC);
      
      String userName="admin";
      String password="admin";
      String host="localhost";
      String port="8080";
      client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
            authPrefs);

      // Use preemptive authentication
      Credentials defaultcreds = new UsernamePasswordCredentials(userName,
            password);
      // set credentials
      client.getState().setCredentials(
            new AuthScope(host, Integer.parseInt(port)), defaultcreds);
      
   }


   
   private void postMethod(HttpServletRequest request,HttpServletResponse response) {
      String filePath=request.getParameter("filePath");
      System.out.println("File Path: "+filePath);
      authenticateUser();
      String url = "http://localhost:8080/alfresco/service/api/upload";
      
      NameValuePair[] data = {new NameValuePair("filename", filePath),
      new NameValuePair("mimetype", "pdf"),
      new NameValuePair("containerId", "7018a7e3-d366-4389-84c6-bd79d793c270")}; //Company Homes' Id
      postMethodUpload(url,data);
         
   }
   
   public void postMethodUpload(String url, NameValuePair[] data) {
      PostMethod post = new PostMethod(url);
      post.setRequestBody(data);
      
      try {
         int statusCode = client.executeMethod(post);
         System.out.println(statusCode);
         if(statusCode==401)
         {
            System.out.println("Getting Exception……………");
            
         }
         
      } catch (HttpException e) {
         
         e.printStackTrace();
      } catch (IOException e) {
         
         e.printStackTrace();
      }
      
   }