mule从s3存储桶下载所有文件

时间:2015-04-04 20:02:36

标签: mule mule-studio mule-el

<flow name="listobjects">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="listobjects" contentType="text/plain" doc:name="HTTP"/>
    <s3:list-objects config-ref="Amazon_S3" bucketName="demo"  doc:name="Amazon S3" maxKeys="5" />

   <!--  <payload-type-filter expectedType="java.util.List" doc:name="Payload"/> -->
    <foreach collection="#[payload]" doc:name="For Each">
   <!-- <foreach doc:name="For Each file"> -->
     <logger message=" inside foreach...... #[payload.getKey()]  ...." level="INFO" doc:name="Logger" />
        <s3:get-object-content config-ref="Amazon_S3" bucketName="demo" key="#[payload.getKey()]"  doc:name="Amazon S3"/>
        <object-to-byte-array-transformer/>
      <file:outbound-endpoint path="C:\output" responseTimeout="10000" doc:name="File" outputPattern="#[payload.getKey()] "></file:outbound-endpoint> 
    </foreach>
</flow>

我的名字叫做demo。 在那个桶里我有3个pdf文件。我想下载所有文件并将其放在c:\ output文件夹中。

我点击了我的网址http://localhost:8081/listobjects

但是我得到了错误:

  

找不到要转换的变换器“CollectionDataType {type = org.mule.module.s3.simpleapi.SimpleAmazonS3AmazonDevKitImpl $ S3ObjectSummaryIterable,itemType = com.amazonaws.services.s3.model.S3ObjectSummary,mimeType =' / '}“to”SimpleDataType {type = org.mule.api.transport.OutputHandler,mimeType =' / '}“。 (org.mule.api.transformer.TransformerException)(org.mule.api.transformer.TransformerException)。消息有效内容的类型为:SimpleAmazonS3AmazonDevKitImpl $ S3ObjectSummaryIterable

1 个答案:

答案 0 :(得分:0)

发生错误是因为在foreach处理器之后,有效负载是S3类的实例,并且您还没有指定要返回的任何Content-Type。因此Mule尝试将S3实例转换为默认的SimpleDataType并失败。 解决它的一种方法就是添加类似

的内容
<set-property propertyName="Content-Type" value="application/json" doc:name="Content-Type" />
<set-payload value="{'result': 'ok'}"/>

最后要明确。

另请注意,在运行后的流程中:

<object-to-byte-array-transformer/>

S3有效负载消失了,因此#[payload.getKey()]将在下一个处理器中失败:

  <file:outbound-endpoint path="C:\output" responseTimeout="10000" doc:name="File" outputPattern="#[payload.getKey()] "></file:outbound-endpoint> 

我没有遇到任何问题:

<flow name="listobjects">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" path="listobjects" contentType="text/plain" doc:name="HTTP"/>
    <s3:list-objects config-ref="Amazon_S3" bucketName="mule_test"  doc:name="Amazon S3" maxKeys="5" />
    <foreach collection="#[payload]" doc:name="For Each">
     <logger message=" inside foreach...... #[payload.getKey()]  ...." level="INFO" doc:name="Logger" />
        <set-variable variableName="fileKey" value="#[payload.getKey()]" doc:name="Variable" />
        <s3:get-object-content config-ref="Amazon_S3" bucketName="#[payload.getBucketName()]" key="#[payload.getKey()]"  doc:name="Amazon S3"/>
        <object-to-byte-array-transformer/>
      <file:outbound-endpoint path="/tmp" responseTimeout="10000" doc:name="File" outputPattern="#[flowVars.fileKey] "></file:outbound-endpoint> 
    </foreach>
    <set-property propertyName="Content-Type" value="application/json" doc:name="Content-Type" />
    <set-payload value="{'result': 'ok'}"/>
</flow>