cancel
Showing results for 
Search instead for 
Did you mean: 

Empty document content on CMIS java client

cmisnewb
Champ in-the-making
Champ in-the-making
Hi,

sorry if this is a repeated topic; I've found something similar but not exactly the same case. I'm writing a java client to integrate CMIS with my application. My createDocument method seems to work fine, I can see the document on Alfresco interface, but its size is 0 bytes, and the content is empty. Not sure if this is an Alfresco or CMIS issue (I'm working on Alfresco 3.3). Any suggestion would be welcomed…

Code snipet:



        BigInteger length = new BigInteger(new Long(IOUtils.toByteArray(is).length).toString());
         Map<String, Object> properties = new HashMap<String, Object>();
         properties.put(PropertyIds.NAME, documentName);
         properties.put(PropertyIds.OBJECT_TYPE_ID, documentObjectType);
         
         String mimeType = URLConnection.getFileNameMap().getContentTypeFor(documentName);
         if (StringUtils.isEmpty(mimeType)) {
            String extension = getDocumentExtension(documentName);
            if (StringUtils.isEmpty(extension)) {
               mimeType = "plain/text";
            } else {
               mimeType = "application/" + extension;
            }
         }
         ContentStream content = new ContentStreamImpl(documentName, length, mimeType, is);          
         folder.createDocument(properties, content, VersioningState.NONE, null, null, null, getSession().getDefaultContext());


Thanks!
2 REPLIES 2

rwetherall
Confirmed Champ
Confirmed Champ
By making the call to  toByteArray(InputStream input) you have already read the contents of your input stream.

When it is passed to CMIS there is no content to read, hence length 0.

Cheers,
Roy

cmisnewb
Champ in-the-making
Champ in-the-making
Ups! I knew I was missing something really dumb Smiley Sad I'll give it a try, thank you very much!