It's all about the answers!

Ask a question

How can I read an attachment with the serverside api

Kevin Eifinger (1211610) | asked Nov 06 '14, 9:09 a.m.
edited Nov 06 '14, 9:10 a.m.
Hi all,
for customization project I want to download a workitem attachment to a directory on the server.

Reading Ralphs blog post I know how to download and read an attachment for the client side:

But I want to try to do it as a serverside plugin where contentManager is not available. I found the following article describing the server side version to read files:

However, IServerSideVersionedContentService needs input of type IVersionable.

How can I download/read IAttachment using the server API?

Thank you!

Accepted answer

permanent link
sam detweiler (12.5k6189201) | answered Nov 06 '14, 9:22 a.m.
edited Nov 06 '14, 9:25 a.m.
you can use the IAuditableCommon service

fAuditableCommon = getService(IAuditableCommon.class);

OutputStream os = new ByteArrayOutputStream();

fAuditableCommon.retrieveContent(iattachment.getContent(), os, monitor)

that gives you the binary data of the attachment
Kevin Eifinger selected this answer as the correct answer

Kevin Eifinger commented Nov 06 '14, 9:29 a.m.

Thank you!! 

sam detweiler commented Nov 06 '14, 9:33 a.m.

note that you may need to add the IAuditableCommon class to your plugin dependencies list in plugin.xml

Your answer

Register or to post your answer.