AnsweredAssumed Answered

problem upload a file.doc

Question asked by yassine_036 on Jul 15, 2009
hello i'm using jsp page for uploading a files, i can upload a pdf file or text file but i can't it with word file i don't know why, it uploads in alfresco but the file is not the same file that i have on my dick, when i download it word give me a message that the file is corrupted and i have to download a converter
this is my page jsp with i upload files:
 InputStream is= request.getInputStream();
      AuthenticationUtils.startSession("admin", "admin");
      Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
      String folderPath = "/app:company_home/cm:yassine_test";
      ParentReference companyHomeParent = new ParentReference(storeRef, null,
            folderPath, Constants.ASSOC_CONTAINS, null);

      RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory
      ContentServiceSoapBindingStub contentService = WebServiceFactory
      NamedValue[] contentProps = new NamedValue[1];
      NamedValue[] titledProps = new NamedValue[2];

      // le nom du fichier

      CMLCreate create = new CMLCreate("1", companyHomeParent,
            companyHomeParent.getUuid(), Constants.ASSOC_CONTAINS, null,
            Constants.PROP_CONTENT, contentProps);
      // Construct CML Block
      contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME,

      // Propriété du fichier
      titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE,

      titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, "");

      CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED,
            titledProps, null, "1");

      String contType = "application/msword";
      CML cml = new CML();
      cml.setCreate(new CMLCreate[] { create });
      cml.setAddAspect(new CMLAddAspect[] { addAspect });
      // Mettre a jour le repositroy

      ContentFormat format = new ContentFormat(contType, "UTF-8");

      UpdateResult[] result = WebServiceFactory.getRepositoryService()
      Reference content = result[0].getDestination();

      byte[] buffer = new byte[32];
      ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

      int l = 0;
      while (l >= 0) {
         l =;
         if (l != -1) {
            os.write(buffer, 0, l);
      contentService.write(content, Constants.PROP_CONTENT, os.toByteArray(),

thank you for your help