vamsiampolu
vamsiampolu

Reputation: 6642

Apache Nifi PutFTP change extension of file

I transform csv data to json and write that information to PutFTP, the extension of the file output is csv and not json. How can I override this information for the PutFTP processor.

Upvotes: 3

Views: 2595

Answers (3)

Trilliji
Trilliji

Reputation: 61

I agree that the UpdateAttribute worked well but struggled to find an expression that worked with it. After some testing and research I arrived at this solution.

${filename:substringBeforeLast('.'):append('.json')}

Upvotes: 4

Petro
Petro

Reputation: 3662

A more dynamic answer when using UpdateAttribute is to use NiFi expressions to change the filename:

So to change dynamc_name.txt to dynamc_name.json

Set your NiFi UpdateAttribute filename to:

${filename:substring(0,11).json} 

enter image description here

Expression                                              Value

${filename:substring(0,1)}                              a

${filename:substring(2)}                                brand new filename.txt

${filename:substring(12)}                               filename.txt

${filename:substring( ${filename:length():minus(2)} )}  xt

Reference: https://docs.cloudera.com/HDPDocuments/HDF3/HDF-3.0.2/bk_expression-language/content/substring.html

Upvotes: 2

Andy
Andy

Reputation: 14194

Use an UpdateAttribute processor to change the filename attribute of the flowfile from example.csv to example.json.

Upvotes: 4

Related Questions