AnsweredAssumed Answered

Upload custom properties during File Upload

Question asked by jlabuelo on Jun 4, 2015
Hi there

We have build a Java code to upload a file to a defined folder in Alfresco. This code has been done to cretae an integration between an Idependent Java System and Alfresco. We are able to upload the file from the external system to Alfresco, and also to set up the custom Type of the content file we are uploading…. however we also would like to define some of the custom properties of the file during its upload process, but do not how?

Here is our code

private void mainUpload() {
      try {
         //pasamos el FileInputStream a File
         this.file = toFile(this.fileobj);
         String alfrescoTiccketURL = url + "login?u=" + this.login + "&pw=" + this.password;
         Authentication ticket = new Authentication();
         String authTicket = ticket.getTicket(alfrescoTiccketURL);
         String urlString = this.url + "upload?alf_ticket=" + authTicket;
         System.out.println("The upload url:::" + urlString);
         HttpClient client = new HttpClient();
         PostMethod mPost = new PostMethod(urlString);
         Part[] parts = {
               new FilePart("filedata", this.filename, file, this.filetype, null),
               new StringPart("filename", this.filename),
               new StringPart("description", this.description),
               new StringPart("destination", this.destination),
                 new StringPart("contenttype", "hula:hulaType"),
                 new StringPart("hula:departamento", this.departament)

         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());
         System.out.println("File: " + this.filename + " upload successfully!!");
      } catch (Exception e) {

however the lines

new StringPart("description", this.description),
new StringPart("hula:departamento", this.departament)

They do not work. Description is not a custom property, however hula:departamento is a property of the type "hula:hulaType"… but both do not get updated once the document is uploaded.

Also we have tried to upload the file using

new StringPart("uploaddirectory", "/Company Home/UPLOADED")

but it did not work either… and we have had to use new StringPart("destination", this.destination), where the destination is the noderef of the folder… and this is a problem also as we need to know the noderef of the destination dinamically, as the files are not always uploaded to the same directoy.

Anyway, my doubts here are

a)How can I upload the file with the custom type and custom properties??

b) How can I upload the file using the folder path like new StringPart("uploaddirectory", "/Company Home/UPLOADED")??

Thanks a lot