Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created on
12-06-2016
04:45 AM
- last edited on
06-01-2026
11:29 PM
by
VidyaSargur
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.