Howto Change Mimetype for Existing Content

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2009 01:07 PM
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
Method 2: Using the ContentReader
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);
Labels:
- Labels:
-
Archive
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2009 05:25 AM
I'm not sure. That's how I would try it. It could be a defect.
Perhaps that only works if you're actually going to go ahead and write something using the channel you get from the ContentWriter…?
It would be a shame to stream the content out and then back in though.
Maybe try opening up random access channel and then force write-flush, with the 'metadata' param as true:
fileChannel = contentWriter.getFileChannel(false);
contentWriter.setMimetype("text/plain");
fileChannel.force(true);
fileChannel.close();
…?
Perhaps that only works if you're actually going to go ahead and write something using the channel you get from the ContentWriter…?
It would be a shame to stream the content out and then back in though.
Maybe try opening up random access channel and then force write-flush, with the 'metadata' param as true:
fileChannel = contentWriter.getFileChannel(false);
contentWriter.setMimetype("text/plain");
fileChannel.force(true);
fileChannel.close();
…?

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2009 07:16 AM
You can set the mimetype using the NodeService instead:
It seems, that the ContentReader or ContentWriter .setMimetype method is only usable for creating new content. Might be a bug or a feature 😎
Regards,
lothar
ContentData cd = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);ContentData newCD = ContentData.setMimetype(cd, "other/mimetype");nodeService.setProperty(nodeRef, ContentModel.PROP_CONTENT, newCD);
It seems, that the ContentReader or ContentWriter .setMimetype method is only usable for creating new content. Might be a bug or a feature 😎
Regards,
lothar
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2009 07:18 AM
Of course! Thank you.
