【问题标题】:mule download all files from s3 bucketmule 从 s3 存储桶下载所有文件
【发布时间】:2015-04-14 04:40:23
【问题描述】:
<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='/ '}”到“SimpleDataType{type=org.mule.api.transport.OutputHandler, mimeType='/'}”。 (org.mule.api.transformer.TransformerException) (org.mule.api.transformer.TransformerException)。消息负载的类型为:SimpleAmazonS3AmazonDevKitImpl$S3ObjectSummaryIterable

【问题讨论】:

    标签: mule mule-studio mule-el


    【解决方案1】:

    发生错误是因为在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>
    

    【讨论】:

      猜你喜欢
      • 2015-11-02
      • 1970-01-01
      • 2015-05-20
      • 2017-02-16
      • 2013-10-15
      • 2019-09-06
      • 1970-01-01
      • 1970-01-01
      • 2019-05-30
      相关资源
      最近更新 更多