I have the following folder structure in a S3 bucket called "test-files":
pending-files/products
pending-files/prices
Each folder contains a number of small CSV files and I want to retrieve them all in one call and then process each file in a For Each loop which contains a Choice component to redirect the payload based on the folder name e.g. "products" or "price".
I use List Objects to retrieve the files and have been able to retrieve all the files but the list contains an entry for the folder and the For Each will fail validation due to the folder not being a valid CSV file and also will fail the empty file check because the size will be 0.
How can I do this?
XML Workflow:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:s3="http://www.mulesoft.org/schema/mule/s3" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/s3 http://www.mulesoft.org/schema/mule/s3/current/mule-s3.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<flow name="listobjects">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="1000" timeUnit="HOURS"/>
<s3:list-objects config-ref="Amazon_S3__Configuration" bucketName="test-files" prefix="pending-files/" maxKeys="5" doc:name="Amazon S3" delimiter="/" marker="pending-files/"/>
</poll>
<foreach collection="#[payload.objectSummaries]" doc:name="For Each">
<logger message="#[payload.getKey()]" level="INFO" doc:name="Logger"/>
<s3:get-object-content config-ref="Amazon_S3__Configuration" bucketName="test-file-drop" key="#[payload.getKey()]" mimeType="application/csv" doc:name="Amazon S3"/>
<choice doc:name="Choice">
<when expression="">
<flow-ref name="csvToMongodbFlow" doc:name="csvToMongodbFlow"/>
</when>
<otherwise>
<logger message="#['*************Missed*****************']" level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
</foreach>
<logger message="#['\nCompleted']" level="INFO" doc:name="Logger"/>
</flow>
</mule>