我的目标是访问我之前上传的 pdf 类型的执行变量,然后使用服务任务中引用的 Java 类将此 pdf 作为电子邮件中的附件发送。
^我的目标 pdf 是“proofOfRequestFile”。它的二进制数据在“pdf”中
尝试1:
FileValue pdfVariable = (FileValue) delegateExecution.getVariable("proofOfRequestFile");
返回错误:
类 java.io.ByteArrayInputStream 无法转换为类 org.camunda.bpm.engine.variable.value.FileValue (java.io.ByteArrayInputStream 位于加载程序“bootstrap”的模块 java.base 中;org.camunda.bpm。 engine.variable.value.FileValue 位于加载器 org.springframework.boot.loader.LaunchedURLClassLoader @4f7d0008) 的未命名模块中
PS:使用(File)而不是(FileValue)会返回相同的错误
尝试2:
byte[] pdfBytes = (byte[]) delegateExecution.getVariable("proofOfRequestFile");
返回错误:
类 java.io.ByteArrayInputStream 无法转换为类 [B(java.io.ByteArrayInputStream 和 [B 位于加载程序“bootstrap”的 java.base 模块中)
尝试3:
我尝试使用包含pdf的二进制变量(如上图所示)
byte[] pdfBytes = (byte[]) execution.getVariable("pdf");
返回错误: 类 java.lang.String 无法转换为类 [B(java.lang.String 和 [B 位于加载程序 'bootstrap' 的 java.base 模块中)
改用 DelegateExecution 的 getVariableTyped 方法。然后,您将获得变量的类型化版本,您可以在其中探索类型并访问正确的值。 它还支持第二个参数来反序列化该值(我不确定这是否是只有一个参数的方法的默认值)。 在您的第三次尝试中,变量的类型是 String,因此您必须将其作为字符串访问并对其进行解码。