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!
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!