1

I am using Mule 4 and Anypoint Studio 7.

I looking to get a list of objects from an AWS S3 bucket, read each xlsx file and transform the message so it is has some new column names.

When I do this I get an error:

Unable to call any overload of function `Value Selector` with arguments (Binary, "Sheet 1") overloads

How can I resolve this error?

Excel File in S3 Bucket:

enter image description here

Workflow:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:s3="http://www.mulesoft.org/schema/mule/s3"
    xmlns:sftp="http://www.mulesoft.org/schema/mule/sftp"
    xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/sftp http://www.mulesoft.org/schema/mule/sftp/current/mule-sftp.xsd
http://www.mulesoft.org/schema/mule/s3 http://www.mulesoft.org/schema/mule/s3/current/mule-s3.xsd">
    <flow name="aws-flow" doc:id="21bd363a-166e-4fc2-9246-dd6f48763db7" >
        <scheduler doc:name="Scheduler" doc:id="4e3bf7a7-99ce-44e3-b732-fece4200c5b6" >
            <scheduling-strategy >
                <fixed-frequency frequency="10000000"/>
            </scheduling-strategy>
        </scheduler>
        <s3:list-objects doc:name="List objects AWS S3 bucket" doc:id="640ed7a3-2e0f-4c5d-99a1-fd503d02f055" config-ref="Amazon_S3_Configuration" bucketName="${aws.s3.bucket.name}"/>
        <foreach doc:name="For Each" doc:id="f0989986-2d2e-4cc9-b51e-d61cf9d01210" >
            <choice doc:name="Choice" doc:id="9f47cc0e-d784-4dcb-83a6-07e553997aab" >
                <when expression='#[payload.key endsWith ".xlsx"]'>
                    <s3:get-object doc:name="Get object from AWS S3" doc:id="568ed3c4-d7f8-4657-a515-835e5671b72c" config-ref="Amazon_S3_Configuration" bucketName="#[payload.bucketName]" key="#[payload.key]" />
                    <ee:transform doc:name="Transform Message" doc:id="966cf917-d50d-4858-8e26-9f381bc57de4">
                        <ee:message>
                            <ee:set-payload><![CDATA[%dw 2.0
output application/xlsx
---
{
    "Sheet 1": payload[0] map ( sheet1 , indexOfSheet1 ) -> {
        EmployeeId: sheet1.EmployeeId default "" as String,
        Name: sheet1.Name default "" as String,
    }
}]]></ee:set-payload>
                        </ee:message>
                    </ee:transform>
                    <logger level="INFO" doc:name="Log Payload" doc:id="f3738738-d56d-4930-94f8-763aea3b5dbe" message='#[payload]'/>
                </when>
                <otherwise >
                    <logger level="INFO" doc:name="Log File Invalid" doc:id="e3f5c9c2-0b75-4b1c-88dc-cb1ae1e2f249" message="Invalid file"/>
                </otherwise>
            </choice>
        </foreach>
    </flow>
</mule>
user3165854
  • 1,505
  • 8
  • 48
  • 100

1 Answers1

1

the problem is that the S3 connector is not setting the mime type to "application/xlsx" so DW instead of parsing it as a ExcelFile it takes it as Binary content.

There is a simple solution

after

<s3:get-object doc:name="Get object from AWS S3" doc:id="568ed3c4-d7f8-4657-a515-835e5671b72c" config-ref="Amazon_S3_Configuration" bucketName="#[payload.bucketName]" key="#[payload.key]" />

add

<set-payload value="#[payload]" mimeType="application/xlsx"/>
machaval
  • 4,969
  • 14
  • 20
  • Thanks that seems to be processing it correctly. I am still seeing the error in Dataweave and not sure if its because the in the input panel it shows as "binary". Is there a way to change this? I don't seem to have the option to "Clear Metadata" so looks like I will need to define a metadata type for the spreadsheet and write out all the fields. – user3165854 Jan 30 '19 at 15:04
  • did they take away input payload? i.e. – utechtzs Jan 30 '19 at 16:41
  • That and input payload application/xlsx doesn't seem to make a difference. I'm also seeing the same error when I set a variable value with #[(payload.key splitBy("."))[0]]. Both that and the dataweave code is highlighted in red but both seem to work when I deploy the application. Would like to be able to get the errors removed. – user3165854 Jan 30 '19 at 17:07
  • If you see the error on MuleStudio then is because you need to set the metadata. – machaval Jan 30 '19 at 19:09