File Writer

Discover more about the File Writer component and how to use it on the Digibee Integration Platform.

File Writer allows information to be written in a file.

Parameters

Take a look at the configuration parameters of the component. Parameters supported by Double Braces expressions are marked with (DB).

ParameterDescriptionDefault valueData type

File Name (DB)

File name or full file path (i.e. tmp/processed/file.txt) of the file to be generated by the component with the input information.

data.csv

String

Data (DB)

Determines the data that must be written in the file generated by the component. The field accepts an array of strings or a simple string. If it’s an array, each item will be recorded in a new line. If the content is an object (and not a string), then the Coalesce property must be enabled to avoid an error occurrence.

{{ message.data }}

String

Policy For When File Already Exists

Parameter in which the behavior to be followed is configured if a file with the same name already exists in the current execution. Options: Append (data added in the existing file), Override (existing file is overridden), Fail (flow is interrupted by an error).

Append

String

End of Line Policy

Determines the use of end-of-line characters policy. Options: Windows (2 characters for end of line - CR + LF), Unix (only 1 character for end of line - LF), None (no character applies).

Windows

String

Charset

Determines the characters code to be used for file creation.

UTF-8

String

Binary File

If the data input for the component (determined in the Data parameter) is a base64-type string and this option is enabled, then the text will be converted and recorded in the file.

False

Boolean

Coalesce

If the option is enabled and the value of an input message corresponds to an object/array, the informed data will be accepted by the component, and the file will be successfully recorded. Otherwise, when receiving a value as an object/array, an error will be presented as a result, and "false" will be shown for the "success" property.

False

Boolean

Fail On Error

If the option is enabled, the execution of the pipeline with an error will be interrupted; otherwise, the pipeline execution proceeds, but the result will show a false value for the "success" property.

False

Boolean

Files manipulation in the pipeline

The pipeline has a local and temporary area for the files manipulation, which is separated and validated only during the flow execution.

That way, you must understand the access to the files as if it was made in a virtual file system. The files names can have any valid character and file extensions, which can also have a relative directory.

For example: data.csv or processing/data.csv.

Any attempt to access other absolute directories will be blocked during the pipeline execution.

Messages flow

Input

The component accepts any input message, being able to use it through Double Braces.

Output

The component returns a JSON containing the name of the created file and the success property containing the value true.

  • Without error

{
"fileName": "data.csv",
"success": true
}
  • With error

{
"success": false,
"message": "File data.csv already exists.",
"exception":
"com.digibee.pipelineengine.exception.PipelineEngineRuntimeException"
}

File Writer in Action

You’ll see below how the component behaves in determined situations and what its respective configuration is.

Create txt file with a string sent by Double Braces

For this example, a static data input will be used and, by the end, the file will be read with the File Reader component.

The File Writer component will be configured the following way:

  • File Name: booklist.txt

  • Data: {{ message.data }}

  • Policy For When File Already Exists: Append

  • End of Line Policy: Windows

  • Charset: UTF-8

  • Binary File: deactivated

  • Coalesce: deactivated

  • Fail on Error: deactivated

Input

{
"data": "To Kill a Mockingbird\n1984\nHarry Potter and the Philosopher’s Stone\nThe Lord of the Rings\nThe Great Gatsby\nPride and Prejudice\nThe Diary Of A Young Girl\nThe Book Thief\nThe Hobbit\nLittle Women\nFahrenheit 451\nJane Eyre\nAnimal Farm\nGone with the Wind\nThe Catcher in the Rye\nCharlotte’s Web\nThe Lion, the Witch\nThe Grapes of Wrath\nLord of the Flies\nThe Kite Runner\nOf Mice and Men\nA Tale of Two Cities\nRomeo and Juliet\nThe Hitchhikers Guide to the Galaxy\nWuthering Heights\nThe Color Purple\nAlice in Wonderland\nFrankenstein\nThe Adventures of Huckleberry Finn\nSlaughterhouse-Five"
}

Output

{
"fileName": "booklist.txt",
"success": true
}
  • fileName: name of the written file.

  • success: if “true”, the operation has been successfully executed; if “false”, the Fail On Error property was enabled.

Created file reading

{"data": ["To Kill a Mockingbird","1984","Harry Potter and the Philosopher’s Stone","The Lord of the Rings","The Great Gatsby","Pride and Prejudice","The Diary Of A Young Girl","The Book Thief","The Hobbit","Little Women","Fahrenheit 451","Jane Eyre","Animal Farm","Gone with the Wind","The Catcher in the Rye","Charlotte’s Web","The Lion, the Witch","The Grapes of Wrath","Lord of the Flies","The Kite Runner","Of Mice and Men","A Tale of Two Cities","Romeo and Juliet","The Hitchhikers Guide to the Galaxy","Wuthering Heights","The Color Purple","Alice in Wonderland","Frankenstein","The Adventures of Huckleberry Finn","Slaughterhouse-Five"],"fileName": "booklist.txt","lineCount": 30}

Create txt file with a data in base64 that will be converted when recording the file

For this example, a static data input will be used and, by the end, the file will be read with the File Reader component.

The File Writer component will be configured the following way:

  • File Name: booklist.txt

  • Data: {{ message.data }}

  • Policy For When File Already Exists: Append

  • End of Line Policy: Windows

  • Charset: UTF-8

  • Binary File: activated

  • Coalesce: deactivated

  • Fail on Error: deactivated

Input

{
"data": "VG8gS2lsbCBhIE1vY2tpbmdiaXJkCjE5ODQKSGFycnkgUG90dGVyIGFuZCB0aGUgUGhpbG9zb3BoZXLigJlzIFN0b25lClRoZSBMb3JkIG9mIHRoZSBSaW5ncwpUaGUgR3JlYXQgR2F0c2J5ClByaWRlIGFuZCBQcmVqdWRpY2UKVGhlIERpYXJ5IE9mIEEgWW91bmcgR2lybApUaGUgQm9vayBUaGllZgpUaGUgSG9iYml0CkxpdHRsZSBXb21lbgpGYWhyZW5oZWl0IDQ1MQpKYW5lIEV5cmUKQW5pbWFsIEZhcm0KR29uZSB3aXRoIHRoZSBXaW5kClRoZSBDYXRjaGVyIGluIHRoZSBSeWUKQ2hhcmxvdHRl4oCZcyBXZWIKVGhlIExpb24sIHRoZSBXaXRjaApUaGUgR3JhcGVzIG9mIFdyYXRoCkxvcmQgb2YgdGhlIEZsaWVzClRoZSBLaXRlIFJ1bm5lcgpPZiBNaWNlIGFuZCBNZW4KQSBUYWxlIG9mIFR3byBDaXRpZXMKUm9tZW8gYW5kIEp1bGlldApUaGUgSGl0Y2hoaWtlcnMgR3VpZGUgdG8gdGhlIEdhbGF4eQpXdXRoZXJpbmcgSGVpZ2h0cwpUaGUgQ29sb3IgUHVycGxlCkFsaWNlIGluIFdvbmRlcmxhbmQKRnJhbmtlbnN0ZWluClRoZSBBZHZlbnR1cmVzIG9mIEh1Y2tsZWJlcnJ5IEZpbm4KU2xhdWdodGVyaG91c2UtRml2ZQ=="
}

Output

{
"fileName": "booklist.txt",
"success": true
}

Created file reading

{
"data": [
"To Kill a Mockingbird",
"1984",
"Harry Potter and the Philosopher’s Stone",
"The Lord of the Rings",
"The Great Gatsby",
"Pride and Prejudice",
"The Diary Of A Young Girl",
"The Book Thief",
"The Hobbit",
"Little Women",
"Fahrenheit 451",
"Jane Eyre",
"Animal Farm",
"Gone with the Wind",
"The Catcher in the Rye",
"Charlotte’s Web",
"The Lion, the Witch",
"The Grapes of Wrath",
"Lord of the Flies",
"The Kite Runner",
"Of Mice and Men",
"A Tale of Two Cities",
"Romeo and Juliet",
"The Hitchhikers Guide to the Galaxy",
"Wuthering Heights",
"The Color Purple",
"Alice in Wonderland",
"Frankenstein",
"The Adventures of Huckleberry Finn",
"Slaughterhouse-Five"
],
"fileName": "booklist.txt",
"lineCount": 30
}

Create txt file with an input data made through a multilevel JSON

For this example, a static data input will be used and, by the end, the file will be read with the File Reader component.

The File Writer component will be configured the following way:

  • File Name: product.txt

  • Data: {{ message.data }}

  • Policy For When File Already Exists: Append

  • End of Line Policy: Windows

  • Charset: UTF-8

  • Binary File: deactivated

  • Coalesce: activated

  • Fail on Error: deactivated

Input

{
"data": {
"products": [
{
"name": "Samsung 4k Q60T 55",
"price": 3278.99
},
{
"name": "Samsung galaxy S20 128GB",
"price": 3698.99
}
]
}
}

Output

{
"fileName": "product.txt",
"success": true
}

Created file reading

{
"data": [
"{\"products\":[{\"name\":\"Samsung 4k Q60T 55\",\"price\":3278.99},{\"name\":\"Samsung galaxy S20 128GB\",\"price\":3698.99}]}"
],
"fileName": "product.txt",
"lineCount": 1
}

That way, the multilevel JSON informed to the component will be inserted as a single line in the TXT file.

Existing file in the execution will the failure policy

For this example, two File Writer components will be configured, one after the other with the options.

The File Writer component will be configured the following way:

  • File Name: booklist.txt

  • Data: {{ message.data }}

  • Policy For When File Already Exists: Fail

  • End of Line Policy: Windows

  • Charset: UTF-8

  • Binary File: deactivated

  • Coalesce: deactivated

  • Fail on Error: deactivated

By the end, the canvas will have the following format:

Input

{
"data": "To Kill a Mockingbird\n1984\nHarry Potter and the Philosopher’s Stone\nThe Lord of the Rings\nThe Great Gatsby\nPride and Prejudice\nThe Diary Of A Young Girl\nThe Book Thief\nThe Hobbit\nLittle Women\nFahrenheit 451\nJane Eyre\nAnimal Farm\nGone with the Wind\nThe Catcher in the Rye\nCharlotte’s Web\nThe Lion, the Witch\nThe Grapes of Wrath\nLord of the Flies\nThe Kite Runner\nOf Mice and Men\nA Tale of Two Cities\nRomeo and Juliet\nThe Hitchhikers Guide to the Galaxy\nWuthering Heights\nThe Color Purple\nAlice in Wonderland\nFrankenstein\nThe Adventures of Huckleberry Finn\nSlaughterhouse-Five"
}

Output

{
"success": false,
"message": "File booklist.txt already exists.",
"exception": "com.digibee.pipelineengine.exception.PipelineEngineRuntimeException"
}
  • success: “false” when the operation fails.

  • message: message about the error.

  • exception: information about the error.

Last updated