Skip to content

Commit 057108a

Browse files
docs: add save to file component example (#7651)
* save-to-file-component-example * cleanup * Apply suggestions from code review Co-authored-by: KimberlyFields <[email protected]> * add-tip-on-format --------- Co-authored-by: KimberlyFields <[email protected]>
1 parent ee35003 commit 057108a

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

docs/docs/Components/components-processing.md

+76
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,82 @@ This component converts and extracts JSON fields using JQ queries.
389389
|------|--------------|------|
390390
| filtered_data | Filtered Data | Filtered data as list of [Data](/concepts-objects#data-object) objects. |
391391

392+
393+
## Save to File
394+
395+
This component saves [DataFrames, Data, or Messages](/concepts-objects) to various file formats.
396+
397+
1. To use this component in a flow, connect a component that outputs [DataFrames, Data, or Messages](/concepts-objects) to the **Save to File** component's input.
398+
The following example connects a **Webhook** component to two **Save to File** components to demonstrate the different outputs.
399+
400+
![Two Save-to File components connected to a webhook](/img/component-save-to-file.png)
401+
402+
2. In the **Save to File** component's **Input Type** field, select the expected input type.
403+
This example expects **Data** from the **Webhook**.
404+
3. In the **File Format** field, select the file type for your saved file.
405+
This example uses `.md` in one **Save to File** component, and `.xlsx` in another.
406+
4. In the **File Path** field, enter the path for your saved file.
407+
This example uses `./output/employees.xlsx` and `./output/employees.md` to save the files in a directory relative to where Langflow is running.
408+
The component accepts both relative and absolute paths, and creates any necessary directories if they don't exist.
409+
:::tip
410+
If you enter a format in the `file_path` that is not accepted, the component appends the proper format to the file.
411+
For example, if the selected `file_format` is `csv`, and you enter `file_path` as `./output/test.txt`, the file will be saved as `./output/test.txt.csv` so the file is not corrupted.
412+
:::
413+
5. Send a POST request to the **Webhook** containing your JSON data.
414+
Replace `YOUR_FLOW_ID` with your flow ID.
415+
This example uses the default Langflow server address.
416+
```text
417+
curl -X POST "http://127.0.0.1:7860/api/v1/webhook/YOUR_FLOW_ID" \
418+
-H 'Content-Type: application/json' \
419+
-d '{
420+
"Name": ["Alex Cruz", "Kalani Smith", "Noam Johnson"],
421+
"Role": ["Developer", "Designer", "Manager"],
422+
"Department": ["Engineering", "Design", "Management"]
423+
}'
424+
```
425+
6. In your local filesystem, open the `outputs` directory.
426+
You should see two files created from the data you've sent: one in `.xlsx` for structured spreadsheets, and one in Markdown.
427+
```text
428+
| Name | Role | Department |
429+
|:-------------|:----------|:-------------|
430+
| Alex Cruz | Developer | Engineering |
431+
| Kalani Smith | Designer | Design |
432+
| Noam Johnson | Manager | Management |
433+
```
434+
435+
### File input format options
436+
437+
For `DataFrame` and `Data` inputs, the component can create:
438+
- `csv`
439+
- `excel`
440+
- `json`
441+
- `markdown`
442+
- `pdf`
443+
444+
For `Message` inputs, the component can create:
445+
- `txt`
446+
- `json`
447+
- `markdown`
448+
- `pdf`
449+
450+
### Inputs
451+
452+
| Name | Display Name | Info |
453+
|------|--------------|------|
454+
| input_type | Input Type | Select the type of input to save.|
455+
| df | DataFrame | The DataFrame to save. |
456+
| data | Data | The Data object to save. |
457+
| message | Message | The Message to save. |
458+
| file_format | File Format | Select the file format to save the input. |
459+
| file_path | File Path | The full file path including filename and extension. |
460+
461+
### Outputs
462+
463+
| Name | Display Name | Info |
464+
|------|--------------|------|
465+
| confirmation | Confirmation | Confirmation message after saving the file. |
466+
467+
392468
## Select data
393469

394470
:::important
272 KB
Loading

0 commit comments

Comments
 (0)