How to update content of the file in Alfresco?
My java-backed webscript copies file in a repository to a temp folder and edits it for my needs. During its work a new content is generated and it must be written to a created temporary file.
But there is a problem: the first nor the second code below does not updates file's content.
ContentWriter contentWriter = this.contentService.getWriter(tempFile,
ContentModel.PROP_CONTENT, true);
contentWriter.putContent(content);
And the second:
`
WritableByteChannel byteChannel = contentWriter.getWritableChannel();
ByteBuffer buffer = ByteBuffer.wrap(content.getB开发者_StackOverflowytes());
byteChannel.write(buffer);
byteChannel.close();
`
How to update file's content?
This works for me:
ContentWriter contentWriter = contentService.getWriter(noderef, ContentModel.PROP_CONTENT, true);
contentWriter.setMimetype("text/csv");
FileChannel fileChannel = contentWriter.getFileChannel(false);
ByteBuffer bf = ByteBuffer.wrap(logLine.getBytes());
try {
fileChannel.position(contentWriter.getSize());
fileChannel.write(bf);
fileChannel.force(false);
fileChannel.close();
} catch (IOException e){
e.printStackTrace();
}
I'm appending a line to an existing file, so logLine is the appending string.
精彩评论