cancel
Showing results for 
Search instead for 
Did you mean: 

Assign custom content type

lordpixel
Champ in-the-making
Champ in-the-making
Hi all
I've succesfully created folder and files on alfresco server using web services API.
I can't assign a custom content type.
For example i have set a content type with this namespace

   <namespaces>
      <namespace uri="mf.modFatture" prefix="mf"/>
   </namespaces>

This is the code I use to write file on Alfresco

ParentReference parentReference = new ParentReference(
                    STORE,
                    Uuid,
                    null,
                    Constants.ASSOC_CONTAINS,
                    Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, idCartella));

            // Create the content
            NamedValue[] properties = new NamedValue[]{Utils.createNamedValue(Constants.PROP_NAME, nomeFile)};


            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);

            // Get the created node and create the format
            Reference newContentNode = result[0].getDestination();
            ContentFormat format = new ContentFormat("image/jpeg", "UTF-8");

            // Open the file and convert to byte array
            //InputStream viewStream = newContentNode.getClass().getClassLoader().getResourceAsStream("c:\\Agenti\\" + nomeFile);


            // Write the content
            InputStream inpStr = new FileInputStream("c:\\Agenti\\" + nomeFile);
            byte[] bytes = ContentUtils.convertToByteArray(inpStr);
            WebServiceFactory.getContentService().write(newContentNode, Constants.PROP_CONTENT, bytes, format);

How can i assign the type mf.modFatture to the file just created??

Thanks
1 REPLY 1

openpj
Elite Collaborator
Elite Collaborator
You have to specify the content type in the CMLCreate object:

String contentType = "{mf.modFatture}yourCustomContentTypeLocalName";
CMLCreate create = new CMLCreate("1", parentReference, null, null, null, contentType, properties);
Hope this helps.