从Camunda任务访问上载的文件

从Camunda任务访问上载的文件,camunda,Camunda,Camunda流程的最终任务必须将用户上传的文件写入特定文件夹。因此,我创建了以下“服务任务”作为流程的最后一个任务: 然后,在Java项目中,我添加了带有以下代码的FinishArchiveDelegate类: package com.ower.abpar.agreements; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDeleg

Camunda流程的最终任务必须将用户上传的文件写入特定文件夹。因此,我创建了以下“服务任务”作为流程的最后一个任务:

然后,在Java项目中,我添加了带有以下代码的
FinishArchiveDelegate
类:

package com.ower.abpar.agreements;

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;

public class FinishArchiveDelegate implements JavaDelegate {

    @Override
    public void execute(DelegateExecution execution) throws Exception {
        System.out.println("Process finished: "+execution.getVariables());
    }
}
当我检查日志时,我发现我可以看到文档名称,如:

document_1 => FileValueImpl [mimeType=image/jpeg, filename=Test_agreement1.jpg, type=file, isTransient=false]
问题是,它只显示文件名,我需要从Camunda的数据库请求它将其复制到另一个文件夹。有什么建议或想法吗


谢谢

经过一些测试,我意识到我不仅可以使用
execution.getVariable(DOCUMENT\u VARIABLE\u name)
获取名称,还可以获取所有上传的文件内容。这就是我所做的:

// Get the uploaded file content
Object fileData = execution.getVariable("filename");

// The following returns a FileValueImpl object with metadata 
// about the uploaded file, such as the name
FileValueImpl fileMetadata = FileValueImpl)execution.getVariableLocalTyped("filename")

// Set the destination file name
String destinationFileName = DEST_FOLDER + fileMetadata.getFilename();
...
// Create an InputStream from the file's content
InputStream in = (ByteArrayInputStream)fileData;
// Create an OutputStream to copy the data to the destination folder
OutputStream out = new FileOutputStream(destinationFileName);

byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
}
in.close();
out.close();
希望这对某人有帮助,干杯