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

Upload attachment to the work item using server api.

Hi All,


I had written a simple code to attach a text file and excel file to the work item using server api.
For this I written follow up action and trigger the action on save operation of work item.

File has been uploaded and link to the work item successfuly but extension is different.
If I download the uploaded file from work item then file extension is of type : 'File'.

Below is the code :
--------------------------
FileInputStream fis= null;
File attachmentFile = new File("D:\serverInfo\sheet1.xlsx");
try{
fis = new FileInputStream(attachmentFile);
IContentService contentService = getService(IContentService.class); 
IAttachment attachment = workItemServer.createAttachment(projectArea, monitor);
attachment.setName("abc");
attachment.setDescription("test");
  
IContent content  = contentService.storeContent3(IContent.CONTENT_TYPE_UNKNOWN, IContent.ENCODING_UTF_8,LineDelimiter.LINE_DELIMITER_NONE,new FileInputStream(attachmentFile), attachmentFile.length(), null, HashCode.createHashCode(new FileInputStream(attachmentFile)));
attachment.setContent(content);
attachment = (IAttachment) attachment.getWorkingCopy();
workItemServer.saveAttachment(attachment, monitor);
IItemReference reference = WorkItemLinkTypes.createAttachmentReference(attachment);
IWorkItemReferences targetReferences = workItemServer.resolveWorkItemReferences(rcn, null);
targetReferences.add(WorkItemEndPoints.ATTACHMENT, reference);

saveWorkitem(rcn, saveParameter, workItemServer,targetReferences);
System.out.println("Create attachment stop");
}catch (Exception e) {
e.printStackTrace();
}finally{
if (fis != null) {
fis.close();
}
}

Please suggest the changes needed in this code so that if I will upload the file using this code and download the file then file extension should be the same while upload the file.


Thanks in Advance.

0 votes



One answer

Permanent link

 I know that this code has worked for me: https://rsjazz.wordpress.com/2012/08/01/uploading-attachments-to-work-items/


Please note, there is no one who can remote debug your code.

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

Question asked: Oct 11 '17, 6:56 a.m.

Question was seen: 1,786 times

Last updated: Oct 11 '17, 8:02 a.m.

Confirmation Cancel Confirm