Read File Node
Overview
The Read File Node is used to read the contents of a specified file from the file system and output it as a string.
If you are using the Rivet SDK, this node requires a native API to be available in the context when the graph is being run. The native API is responsible for providing the functionality to read the contents of a directory.
- Inputs
- Outputs
- Editor Settings
Inputs
Title | Data Type | Description | Default Value | Notes |
---|---|---|---|---|
Path | string | The path of the file to read. This input is only available if Use Path Input is enabled in settings. | N/A | The input will be coerced into a string if it is not a string. |
Outputs
Title | Data Type | Description | Notes |
---|---|---|---|
Content | string | The contents of the file read from the specified path. | If the file does not exist and Error On Missing File is disabled, this output will be an empty string. |
Editor Settings
Setting | Description | Default Value | Use Input Toggle | Input Data Type |
---|---|---|---|---|
Path | The path of the file to read. | (required) | Yes | string |
Use Path Input | If enabled, the path can be provided via the Path input port. | False | No | N/A |
Error On Missing File | If enabled, the node will error if the file does not exist. If disabled, the node will output an empty string if the file does not exist. | False | No | N/A |
Example 1: Read a file from a specified path
- Create a Read File Node and set the
Path
to the path of the file you want to read. - Run the graph. The
Content
output of the Read File Node should contain the contents of the file.
Example 2: Read a file from a dynamic path
- Create a Text Node and set the text to the path of the file you want to read.
- Create a Read File Node and enable the
Use Path Input
setting. - Connect the Text Node to the
Path
input of the Read File Node. - Run the graph. The
Content
output of the Read File Node should contain the contents of the file.
Error Handling
The Read File Node will error if the native API is not available in the context when the graph is being run. It will also error if the file does not exist and the Error On Missing File
setting is enabled. If the file does not exist and the Error On Missing File
setting is disabled, the node will output an empty string.
FAQ
Q: What is a native API?
A: A native API is an object that is responsible for providing native functionality to nodes. It is passed to the context when the graph is being run. The native API must implement the NativeApi
interface, which includes methods for reading directories, reading and writing files, and other native operations. See the API Reference for more information.
Q: Can I read a file from a URL?
A: No, the Read File Node can only read files from the local file system. If you want to read a file from a URL, you can use the HTTP Call Node to make a GET request to the URL.
Q: Can I read a file in a different format, like CSV or XML?
A: The Read File Node will always output the contents of the file as a string. If you want to parse the contents of the file, you can use other nodes like the Extract JSON, Extract YAML, and the Code Node to parse the contents of the file.