Introduction

This is the next part of the last article (Create and Write CSV Files Using File Connector in MuleSoft) of the File Connector series.

In this article, we will learn how to Read Files Using a File Connector in MuleSoft.

Getting Started

Let’s do a quick project setup and include the required global config files; these are the quick steps:

Next, drag and drop HTTP >> Listener from Mule palette to Message flow and give Display Name, select Connector configuration, and enter the Path.

Read Files Using File Connector in MuleSoft

Enter Display Name (HTTP GET) and Select Connector Configuration ([Connector Name]) and Path (Endpoint Path).

Note. Connector configuration is created in a global file.

Also, provide Allowed methods (GET) in Advanced properties.

Read Files Using File Connector in MuleSoft

Next, Drag and Drop File> Read component from the File palette, enter the Display name, and select Connector and File Path. File Path sets the path dynamically to read the file name.

Read Files Using File Connector in MuleSoft

Next, drag and drop Logger from the Core palette and set the payload.

Read Files Using File Connector in MuleSoft

Define payload.

Read Files Using File Connector in MuleSoft

At last, drag and drop Set Payload and define payload.

Read Files Using File Connector in MuleSoft

Let's run the application now.

Read Files Using File Connector in MuleSoft

Open Postman and enter Endpoint to see the output result.

Once the application is deployed, Pass the file name in the endpoint, available in the right folder or whatever folder name you mentioned, and click Send button.

Read Files Using File Connector in MuleSoft

As you can see, we can read file1 data. If you go back into the folder and open the csv file, then the data is the same, which API provides.

Read Files Using File Connector in MuleSoft

What happens if you enter a file name which doesn’t exist in the folder?

Read Files Using File Connector in MuleSoft

The logger is working as expected to provide the proper logging if the given File does not exist.

Conclusion

This article taught us to read CSV files using File Connector in MuleSoft and display results in Postman.