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).

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