How to get Attachment in alfresco?

cancel
Showing results for 
Search instead for 
Did you mean: 
kangkan
Member II

How to get Attachment in alfresco?

How to get Attachment in alfresco?

I did something like this.

public void notify(DelegateTask delegateTask) {

List <Attachment> at = new ArrayList<Attachment>();

String processInstanceId = delegateTask.getProcessInstanceId();

at = delegateTask.getExecution().getEngineServices().getTaskService().getProcessInstanceAttachments(processInstanceId);

}

However it didn't work

1 Reply
gdharley
Intermediate

Re: How to get Attachment in alfresco?

Seems this is a duplicate of :

java - Alfresco Activiti - How get attachment id in alfresco activiti? - Stack Overflow 

If you are using Activiti Enterprise you will need to use the relatedContentService.

Details of how to use this service can be found in the following forum post:

How do you access an uploaded file in a downstream service task?

It does appear you participated in this post, as far as I can tell the answer to your question can be found in the code snippet below:

public void execute(DelegateExecution execution) {
    try {
      String fileVariableName = "myfile"; // Id of 'upload file field' from form in previous User Task
      Class<?> theClass = Class.forName("com.activiti.conf.ApplicationConfiguration");
      AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(theClass);
      RelatedContentService relatedContentService = applicationContext.getBean(RelatedContentService.class);
      List<RelatedContent> contentList = relatedContentService.getFieldContentForProcessInstance(
          execution.getProcessInstanceId(), fileVariableName, 1, 0).getContent();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
  }

Cheers,

Greg