5

Is there any option to write an attribute of a flow file as a content without using the AttributesToJSON processor?

B. Pesevski
  • 461
  • 1
  • 3
  • 9

3 Answers3

11

Depends what the format of the content is and where you want the attribute to go.

If you just want simply get an attribute value in the content and replace whatever was there, then ReplaceText with the Replacement Value of ${my.attribute} will make the flow file content be the value of my.attribute.

Bryan Bende
  • 18,320
  • 1
  • 28
  • 39
0

For the Json you can use JoltTransform (JoltTransformJSON or JoltTransformRecord)

SCouto
  • 7,808
  • 5
  • 32
  • 49
0

I use ExecuteGroovyScript. Use attribute nameOfAttributeToContent in UpdateAttribute before ExecuteGroovyScript to set name of attribute you want to put to content

Script:

import org.apache.commons.io.IOUtils
import java.nio.charset.StandardCharsets

def flowFile = session.get()
if (!flowFile) return
String nameOfAttributeToContent = flowFile.getAttribute('nameOfAttributeToContent')    
String text = flowFile.getAttribute(nameOfAttributeToContent)
flowFile = session.write(flowFile, { outputStream ->
    outputStream.write(text.getBytes(StandardCharsets.UTF_8))
} as OutputStreamCallback)
session.transfer(flowFile, REL_SUCCESS)

Example of using script to put sample data to content

UpdateAttribute properties

nezhi
  • 1
  • 1