Skip to main content
ashsskum
Gold ⭐️
December 6, 2016
Solved

NiFi: Understanding Core FlowFile Attributes: Accessing fileSize and filename in NiFi

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?

kafka-flow-file.jpg

MattWho
MattWhoAnswer
Titanium ⭐️⭐️⭐️
December 6, 2016

@kumar

The default FlowFile attributes include:

entryDate

lineageStartDate

fileSize

filename

path

uuid

The above FlowFile attribute key names are case sensitive.

Thanks,

Matt

3 replies

sunile_manjee
Gold ⭐️
Gold ⭐️
December 6, 2016

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();

Translate
MattWho
Titanium ⭐️⭐️⭐️
MattWhoAnswer
Titanium ⭐️⭐️⭐️
December 6, 2016

@kumar

The default FlowFile attributes include:

entryDate

lineageStartDate

fileSize

filename

path

uuid

The above FlowFile attribute key names are case sensitive.

Thanks,

Matt

Translate
ashsskum
ashsskumAuthor
Gold ⭐️
December 7, 2016

Thank you, that was it! It would good if they get listed in the Attribute tab as well.

Translate