在 Spring Boot 应用程序中使用 aws s3 出站适配器,尝试上传 s3 存储桶中的文件。想在上传文件之前检查存储桶是否可用。如果存储桶不可用,则需要抛出错误。
对此提出建议。
<int-aws:s3-outbound-gateway id="FileChannelS3"
request-channel="filesOutS3CChainChannel"
reply-channel="filesArcChannel"
transfer-manager="transferManager"
bucket-expression="headers.TARGET_BUCKET"
command="UPLOAD">
<int-aws:request-handler-advice-chain>
<ref bean="retryAdvice" />
</int-aws:request-handler-advice-chain>
</int-aws:s3-outbound-gateway>
您可以配置一个S3RemoteFileTemplate
豆并使用它的exists()
API 中的<filter>
:
<bean id="s3RemoteFileTemplate" class="org.springframework.integration.aws.support.S3RemoteFileTemplate">
<constructor-arg ref="s3SessionFactory"/>
</bean>
<int:filter expression="@s3RemoteFileTemplate.exists(headers.TARGET_BUCKET)" throw-exception-on-rejection="true"/>
UPDATE
面临以下异常java.lang.IllegalStateException: 'path' must in pattern [BUCKET/KEY]
.
抱歉,错过了您需要检查是否存在的事实bucket
,而不是里面的物体。
为此,您需要直接使用 Amazon API:
<int:filter expression="@amazonS3.doesBucketExistV2(headers.TARGET_BUCKET)" throw-exception-on-rejection="true"/>
其中一个amazonS3
是一个豆子com.amazonaws.services.s3.AmazonS3
client.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)