Support Questions
Find answers, ask questions, and share your expertise

Save Contents of Flowfile to Variable in Groovy

New Contributor

Quesiton: Using Groovy in ExecuteScript, how can I save contents (a .PST file) from a flowfile to a variable?

 

Background: I'm creating a Groovy script for a ExecuteScript processor to convert PST email files to EML using the apose.email API. My simple nifi flow is GetFile > ExecuteScript > PutFile. GetFile gets a .PST file from my local machine. I have looked through the ExecuteScript cookbook and other questions on this forum and found the syntax to input a string of the flowfile from an input stream, but am struggling with the syntax to pull a file from the flowfile. The FolderInfo class on the next line is looking for a PST file, not a string, and all subsequent methods use the PST file. Really appreciate any help!

 

Beginning of Code:

 

import org.apache.commons.io.IOUtils
import java.nio.charset.StandardCharsets
import groovy.json.JsonSlurper
import com.aspose.email.FolderInfo;
import com.aspose.email.MapiMessage;
import com.aspose.email.MessageInfo;
import com.aspose.email.MessageInfoCollection;
import com.aspose.email.PersonalStorage;
import com.aspose.email.SaveOptions;

def flowFile = session.get()
if (!flowFile) return

PersonalStorage pst = session.read(flowFile, {inputStream ->
	pst = IOUtils.toString(inputStream, StandardCharsets.UTF_8)	
	FolderInfo folderInfo = pst.getRootFolder();

} as InputStreamCallback)

 

 

0 REPLIES 0
Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.