Created 12-06-2016 04:45 AM
How to capture the filesize and the filename, which can be found in the details section of the flowfile? I understand that the filename is listed in the attribute section, but is there a way to know the variable name for filesize?
Created 12-06-2016 02:55 PM
@kumar
The default FlowFile attributes include:
entryDate lineageStartDate fileSize filename path uuid
The above FlowFile attribute key names are case sensitive.
Thanks,
Matt
Created 12-06-2016 05:30 AM
I don't know of any out of box functionality to get file size. You can use the execute script to and script up way to easily grab the file size. Or build a processor to grab content size. Here is what the code for the processor would look like. very simple.
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { final ComponentLog log = getLogger(); final AtomicReference<String> value = new AtomicReference<>(); FlowFile flowfile = session.get(); session.read(flowfile, new InputStreamCallback() { @Override public void process(InputStream in) throws IOException { try{ String outputHandler = context.getProperty(OUTPUTHANDLER).getValue(); String stringToTest = IOUtils.toString(in); // Check length, in characters if that is what you want System.out.println(stringToTest.length()); // prints "11" // Or provided specific encoded sizes ie UTF-8. this can be property driven //String result = stringToTest.getBytes("UTF-8").toString(); value.set(result); }catch(Exception ex){ ex.printStackTrace();
Created 12-06-2016 02:55 PM
@kumar
The default FlowFile attributes include:
entryDate lineageStartDate fileSize filename path uuid
The above FlowFile attribute key names are case sensitive.
Thanks,
Matt
Created 12-06-2016 05:09 PM
Thank you, that was it! It would good if they get listed in the Attribute tab as well.