Hemant
Hemant

Reputation: 61

How to read a .csv file in mulesoft

I am trying to read a csv file in mulesoft, can one tell me how to do that ? How to tell mulesoft which file to read ?

Upvotes: 2

Views: 17492

Answers (12)

Srinivas
Srinivas

Reputation: 92

You can read a csv file by setting the reader-property as given below in transform component.

   <dw:transform-message doc:name="Transform Message">
             <dw:input-payload doc:sample="sample_data\list_csv.csv" mimeType="application/csv">
                 <dw:reader-property name="separator" value="|"/>
                 <dw:reader-property name="header" value="false" />
             </dw:input-payload>

Upvotes: 1

user3366906
user3366906

Reputation: 149

After determining the file name you can use either parse template or Groovy script to read the file.

1. <parse-template location="my-resurce.txt" doc:name="Load resource as a String"/>
2. <scripting:component doc:name="Get file">                                        
    <scripting:script engine="Groovy"><![CDATA[new File('C:/project/src/main/resources/test.csv').getText('UTF-8')]]></scripting:script>
</scripting:component>

Below link has more details about the different approaches to choose from. mule read single file from classpath during flow

Upvotes: -1

Srinivas
Srinivas

Reputation: 92

You need to define a ffd or flat file definition as a scheme definition, set this as metadata of the listener, use dataweave to read the data, and implement your business logic.

For more detailed implementation, please go through this link:
https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-flat-file-schemas

Upvotes: 0

LINI MOL
LINI MOL

Reputation: 1

use transform message component and define metadata add the csv configurations. you can change the header and the limiters and splitters there.

Upvotes: 0

LINI MOL
LINI MOL

Reputation: 1

Drag the endpoint to your flow. click the file endpoint and browse the path under basic settings Provide file name in the Move to pattern field. optionally you can configure the polling frequency and file age.

Upvotes: 0

Mahesh Sharma
Mahesh Sharma

Reputation: 11

To read a file follow the below steps:

Drag the File endpoint to your flow. click the file endpoint and browse the path under basic settings Provide file name in the Move to pattern field. optionally you can configure the polling frequency and file age.

Now as your flow is configured to read the file and you can apply dataweave/transformers to manipulate your data in payload.

Hope this helps

Upvotes: 1

Balwant Kumar Singh
Balwant Kumar Singh

Reputation: 1178

You can find File Name Regex Filter in General Tab of File property. It is used to configure a filter to restrict the files being processed. You can refer the following link for specifying filter based on your requirement.

Please refer the following link to know how to write Regex Filter : syntax for filename-regex-filter pattern in mule

Upvotes: 0

vijay dhanakodi
vijay dhanakodi

Reputation: 175

use a file connector. add file regex expression which format of file you want to read

Upvotes: 0

JoostD
JoostD

Reputation: 744

Everyone is talking about transforming but you are asking how to read.

You will need the File connector, or FTP, SFTP or some SaaS applications maybe.

You can find an example of reading a CSV file with the File connector in Mule here:

https://www.mulesoft.com/exchange#!/importing-csv-into-mongodb

You will specify a path where Mule should poll for files, polling frequency and you can specify a pattern for which files Mule should look with a regex pattern.

https://docs.mulesoft.com/mule-user-guide/v/3.7/file-connector

Upvotes: 3

Prashaant
Prashaant

Reputation: 1

First transform tge csv file to xml.After that you have to use xslt .Inside Xslt you can group based on the languagcode.then send it to file.

Regards Prashanth A

Upvotes: 0

Matias Pentreath
Matias Pentreath

Reputation: 114

It is better to use DataWeave, this depends on the version of the Mule ESB Runtime that you are using.

Since 3.7.0 EE DataMapper has been deprecated and replaced by DataWeave

https://docs.mulesoft.com/mule-user-guide/v/3.7/dataweave-reference-documentation

If you are using an Enterprise version prior to 3.7 you can use DataMapper.

If you are using a Community Runtime you will have to use a Java Component and create the custom code to read it.

Upvotes: 0

RamakrishnaN
RamakrishnaN

Reputation: 367

Two ways you can do this

1) Using Mule Datamapper component (https://docs.mulesoft.com/mule-user-guide/v/3.6/datamapper-flat-to-structured-and-structured-to-flat-mapping)

2) Java component that uses apachi poi api to read CSV file and process.

Thanks & Regards,

Ramakrishna N

Upvotes: 1

Related Questions