AnsweredAssumed Answered

Howto Change Mimetype for Existing Content

Question asked by stevewickii on Jan 21, 2009
Latest reply on Jan 27, 2009 by tommorris
How would I change the mime-type on a piece of existing content?

I have tried several methods and none seem to work.  The program executes with no problem, it just doesn't do anything to the content.

Method 1: Using the ContentWriter
TransactionService transactionService = serviceRegistry.getTransactionService();
RetryingTransactionCallback<Object> exampleWork = new RetryingTransactionCallback<Object>()
{
            public Object execute() throws Exception
            {
                  ContentWriter content = contentService.getWriter(nodeIWantToChange, ContentModel.PROP_CONTENT, true);
                content.setMimetype(MimetypeMap.MIMETYPE_HTML);
                return null;
            }
};
transactionService.getRetryingTransactionHelper().doInTransaction(exampleWork);

Method 2: Using the ContentReader
TransactionService transactionService = serviceRegistry.getTransactionService();
RetryingTransactionCallback<Object> exampleWork = new RetryingTransactionCallback<Object>()
{
            public Object execute() throws Exception
            {
                  ContentReader content = contentService.getReader(nodeIWantToChange, ContentModel.PROP_CONTENT);
                content.setMimetype(MimetypeMap.MIMETYPE_HTML);
                return null;
            }
};
transactionService.getRetryingTransactionHelper().doInTransaction(exampleWork);

Outcomes