Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Downloading RTC attachments on server side

Hello!
I'm trying to extract RTC work item attachments and save them as files. My code looks like next:

      ...
        // Get all references for work item
        IWorkItemReferences wiReferences = getWorkItemReferences(wi,
                iWorkItemCommon);

        // Get attachments from references
        if (wiReferences != null) {
            List<IReference> references = wiReferences
                    .getReferences(WorkItemEndPoints.ATTACHMENT);
            for (IReference iReference : references) {
                IAttachment attachment = getAttachment(iReference);
                if (attachment != null)
                    saveAttachment("/home/homecredit", attachment);
            }
        }


    /**
     * Save the attachment.
     */
    private void saveAttachment(String tmp, IAttachment attachment) {
        try {
            File fileAttach = new File(attachment.getName());
            OutputStream out = new FileOutputStream(fileAttach);
            try {
                IContent content = attachment.getContent();
               
                // ???

            } finally {
                out.close();
            }
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }
    }

  /**
     * Further analyze an item referenced by an URI
     */
    public IAttachment getAttachment(IReference iReference) {
        IAttachment attachment = null;
        URI uri = iReference.createURI();
        try {
            System.out.println(" Resolving URI: " + uri.toString());
            // get the location from the URI
            Location location = Location.location(uri);
            // resolve the item by location
            IAuditableCommon common = getService(IAuditableCommon.class);
            IAuditable referenced = common
                    .resolveAuditableByLocation(location, ItemProfile
                            .createFullProfile(location.getItemType()), null);
            if (referenced instanceof IAttachment)
                attachment = (IAttachment) referenced;
        } catch (TeamRepositoryException e) {
            saveMessageToLog("Can not get attachment because of:\n" + e);
        }
        return attachment;
    }

But I stumbled when I was trying to get the real content of the attachment to save it with output stream. Can somebody help me on this way?
I know about next code on the client side:

    OutputStream out = new FileOutputStream(save);
    teamRepository.contentManager().retrieveContent(attachment.getContent(), out, null);

But I can not use it on the server side!

Thank you very much for any recommendations and simple thoughts!

0 votes



One answer

Permanent link
This is working code for the client: https://rsjazz.wordpress.com/2012/09/21/downloading-attachments-from-work-items/

I would suggest to search the API. I tried with IContentService and had a hit. I have not looked into this server side service, but it might be the way to go.

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938
× 33

Question asked: Sep 24 '14, 1:50 a.m.

Question was seen: 4,989 times

Last updated: Sep 24 '14, 4:35 a.m.

Confirmation Cancel Confirm