AnsweredAssumed Answered

Uploading content as new version of existing content

Question asked by robertoroberto on Dec 20, 2007
Hi, I want to upload a file on repository.
I'm able to do it.
Now…If a file with same name exists, How can upload this file as new version of the same file?Can you help me please?(sorry for my english)
This is my code to write the file:


    File f=new File(name);
       FileInputStream streamFile=new FileInputStream(f);
      System.out.println(f.exists());
      

     // Create a parent reference, this contains information about the association we are createing to the new content and the
     // parent of the new content (the space retrived from the search)
     ParentReference parentReference = new ParentReference(STORE, null, "/app:company_home/app:user_homes/cm:administrator" ,ASSOC_CONTAINS, ASSOC_CONTAINS);
    
     // Define the content format for the content we are adding
     ContentFormat contentFormat = new ContentFormat("application/pdf", "UTF-8");
    
     NamedValue[] properties = new NamedValue[]{Utils.createNamedValue(Constants.PROP_NAME, /*System.currentTimeMillis() + "_" +*/name)};
     CMLCreate create = new CMLCreate("1", parentReference, null, null, null, Constants.TYPE_CONTENT, properties);
     CML cml = new CML();
     cml.setCreate(new CMLCreate[]{create});
     UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);    

     byte[] bytes=ContentUtils.convertToByteArray(streamFile);
   
     Reference newContentNode = result[0].getDestination();
     Content content = contentService.write(newContentNode, Constants.PROP_CONTENT, bytes, contentFormat);

Outcomes