作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 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
bean 并使用它的 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"/>
更新
Facing below exception
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
的 bean客户端。
关于java - 如何在使用出站网关上传文件之前检查 aws s3 存储桶是否可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51867049/
我是一名优秀的程序员,十分优秀!