cancel
Showing results for 
Search instead for 
Did you mean: 

How to get Attachment in alfresco?

kangkan
Champ in-the-making
Champ in-the-making

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 1

gdharley
Elite Collaborator
Elite Collaborator

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