AnsweredAssumed Answered

upload file to userhome folder

Question asked by magarcia_sm on Jun 2, 2015
Hi there

We are using Alfresco 5.0 and also building a JAVA class to act as an integration system to allow other system to upload documents to Alfresco repository. What we would like to do is to upload the document to the userhome space of the user logged in. This is the java code will create the sesion first using an actual alfresco user with his login/password, and once the ticketid is obtained, we would like to upload the document to his userhome space.

So far we have building the code, but we need to obtain the NodeRef of the right userhome folder so java knows where to place the document.

Our code looks like this.


public static void uploadDocument(String authTicket, File fileobj,
         String filename, String filetype, String description,
         String destination) {

      StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
      ResultSet rs =  searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "PATH:""Dont know what to place in here");
      NodeRef userHomeNodeRef = null;
      try
      {
         if (rs.length() == 0)
         {
            throw new AlfrescoRuntimeException("Didn't find right node");
         }
         userHomeNodeRef= rs.getNodeRef(0);
      }
      finally
      {
         rs.close();
      }
      
      try {

         String urlString = "http://localhost:8080/alfresco/service/api/upload?alf_ticket='+ authTicket;
         System.out.println("The upload url:::" + urlString);
         HttpClient client = new HttpClient();

         PostMethod mPost = new PostMethod(urlString);
         // File f1 =fileobj;
         Part[] parts = {
               new FilePart("filedata", filename, fileobj, filetype, null),
               new StringPart("filename", filename),
               new StringPart("description", description),
               new StringPart("destination", "workspace://SpacesStore/"+userHomeNodeRef),
               new StringPart("description", description),
               
            
         };
         mPost.setRequestEntity(new MultipartRequestEntity(parts, mPost.getParams()));
         int statusCode1 = client.executeMethod(mPost);
         System.out.println("statusLine>>>" + statusCode1 + "……"
               + "\n status line \n" + mPost.getStatusLine() + "\nbody \n"
               + mPost.getResponseBodyAsString());
         mPost.releaseConnection();

      } catch (Exception e) {
         System.out.println(e);
      }
   }


but problem here is that we do not know what to place in the Lucene search to obtain the NodeRef of the user home


      ResultSet rs =  searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "PATH:""Dont know what to place in here");


please, could you point us to the right direction??

Thanks a lot

Outcomes