AnsweredAssumed Answered

CMIS REST upload problem with non octet-stream content

Question asked by iblanco on May 21, 2009
Latest reply on Jun 2, 2009 by syberyan
I've developed ( copy pasted from different examples ) a little proof of concept that uploads a file to an Alfresco repository using CMIS's REST API.

It works for content that has type "application/octet-stream" (which is the default content type), but for other content types the file is created in alfresco but its content is empty. If I always set the content type as "application/octet-stream" all the files upload right, but obviously their content type is not correctly set, and of course rules and behavoiurs related to the content type are not triggered.

I haven't found this bug in Jira but I wanted to check here before reporting it as a bug, I might be doing something wrong.

Here you have the code in case you are interested in ( I use mime-utils to obtain the mime type ):

package es.binovo.cmis;

import java.util.Collection;

import eu.medsea.mimeutil.MimeType;
import eu.medsea.mimeutil.MimeUtil;

import sun.misc.BASE64Encoder;

public class ProofOfConcept {

    * @param args
   public static void main(String[] args) {
      ProofOfConcept poc;

      if (args.length != 4) {
         System.err.println("Error: número de parámetros inadecuado.");
               .println("Modo de uso: ProofOfConcept <usuario> <contraseña> http://<cmis_server>:<port>/<cmis-api>/<folder-url>/<children> <fichero_a_subir>");
               .println("Ejemplo: java es.binovo.cmis.ProofOfConcept admin admin http://pruebas.binovo:8180/alfresco/service/api/path/workspace/SpacesStore/Company%20Home/children /usr/share/pixmaps/gnome-term-tiger.png");

      try {
         poc = new ProofOfConcept(args[0], args[1], new URL(args[2]),
               new File(args[3]));
      } catch (Exception e) {
         // TODO Auto-generated catch block

   private URL url;

   private File file;

   private static final String mensaje = "<entry xmlns=\"\" xmlns:cmis=\"\">\n"
         + "\t<title>FILE_NAME</title>\n"
         + "\t<content type=\"MIME_TYPE\">CONTENT</content>\n"
         + "\t<cmis:object>\n"
         + "\t\t<cmis:properties>\n"
         + "\t\t\t<cmis:propertyString cmis:name=\"ObjectTypeId\"><cmis:value>document</cmis:value></cmis:propertyString>\n"
         + "\t\t</cmis:properties>\n" + "\t</cmis:object>\n" + "</entry>\n";
   private String usuario;

   private String password;

   public ProofOfConcept(String usuario, String password, URL url, File file) {
      this.usuario = usuario;
      this.password = password;
      this.url = url;
      this.file = file;

   private void createContent() throws IOException {
      BASE64Encoder encoder = new BASE64Encoder();
      FileInputStream fis = new FileInputStream(file);
      DataInputStream dis = new DataInputStream(fis);
      // Create the byte array to hold the data
      byte[] bytes = new byte[(int) file.length()];

      Collection<MimeType> mimeTypes = MimeUtil.getMimeTypes(file);
      MimeType mimeType = MimeUtil.getMostSpecificMimeType(mimeTypes);
      if(mimeType == null) mimeType = MimeUtil.UNKNOWN_MIME_TYPE;
      System.out.println("Content mime type is: " + mimeType.toString());
      String datos = ProofOfConcept.mensaje;
      datos = datos.replaceFirst("FILE_NAME", file.getName());
      datos = datos.replaceFirst("MIME_TYPE", mimeType.toString());
      datos = datos.replaceFirst("CONTENT", encoder.encode(bytes));
      String auth = encoder.encode((usuario + ":" + password).getBytes());

      URLConnection conn = url.openConnection();
      conn.setRequestProperty("Authorization", "Basic " + auth);
      OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());

      // A ver que nos cuentan.
      String decodedString;

      BufferedReader in = new BufferedReader(new InputStreamReader(conn

      while ((decodedString = in.readLine()) != null) {



UPDATE: It seems that it also works for image/png content type, but not for application/xml or or text/xml , it seems like something related to text formats.