Support Questions

Find answers, ask questions, and share your expertise

NIFI - Validate vame of file

avatar
Explorer

Hello, is possible validate the name of the file to tingest in HDFS? I mean, i need validate the name of the file is correct and the size is > 0, it's possible?

Thanks.

1 ACCEPTED SOLUTION

avatar
Master Guru
@Pepelu Rico

Yes we can validate the name of the file and size of file before ingesting into HDFS by using RouteOnAttribute processor.

in NiFi we are having attributes to the flowfile as

1.${filename} //gets the filename of the flowfile
2.${fileSize} //gets the size in bytes of the flowfile

In RouteOnAttribute processor add new property as

valid_files

${filename:equlas("<required_file_name>"):and(${fileSize:gt(0)})} 

In the above expression we are using NiFi expression language and checking the filename value equlas(expression language function) to <required_file_name> and checking fileSize value is greater than 0, Then only the flowfiles will be tranferred into valid_files relation.

Feed only the valid_files relation to PutHDFS processor, By using this relation we are storing only the files that satisfies the condition will be stored into HDFS.

-

If the Answer helped to resolve your issue, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.

View solution in original post

1 REPLY 1

avatar
Master Guru
@Pepelu Rico

Yes we can validate the name of the file and size of file before ingesting into HDFS by using RouteOnAttribute processor.

in NiFi we are having attributes to the flowfile as

1.${filename} //gets the filename of the flowfile
2.${fileSize} //gets the size in bytes of the flowfile

In RouteOnAttribute processor add new property as

valid_files

${filename:equlas("<required_file_name>"):and(${fileSize:gt(0)})} 

In the above expression we are using NiFi expression language and checking the filename value equlas(expression language function) to <required_file_name> and checking fileSize value is greater than 0, Then only the flowfiles will be tranferred into valid_files relation.

Feed only the valid_files relation to PutHDFS processor, By using this relation we are storing only the files that satisfies the condition will be stored into HDFS.

-

If the Answer helped to resolve your issue, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.