AnsweredAssumed Answered

Alfresco JCR - always sets mimetype to binary

Question asked by jharrop on Mar 31, 2008
If you use the JCR interface to write content, org.alfresco.jcr.item.PropertyImpl.writeValue does:


                ContentService contentService = session.getRepositoryImpl().getServiceRegistry().getContentService();
                ContentWriter writer = contentService.getWriter(node.getNodeRef(), name, true);
                writer.setMimetype(MimetypeMap.MIMETYPE_BINARY);
                writer.putContent((InputStream)value);

In comparison, a WebDAV PUT can use the filename to set the mime type:


            String guessedMimetype = getMimetypeService().guessMimetype(contentNodeInfo.getName());

But PropertyImpl.writeValue does have what it needs to do a better job.

node.getName() could be used in PropertyImpl.writeValue to set the mimetype, for example.


                if (node.getName().endsWith(".xml")) {
                   writer.setMimetype(MimetypeMap.MIMETYPE_XML);
                } else {
                   writer.setMimetype(MimetypeMap.MIMETYPE_BINARY);
                }

It would obviously be better to use the MimetypeService though.

Perhaps Alfresco could add an enhancement along these lines?

cheers

Jason

Outcomes