gpt4 book ai didi

java - 如何在使用出站网关上传文件之前检查 aws s3 存储桶是否可用

转载 作者:行者123 更新时间:2023-11-30 06:03:10 24 4
gpt4 key购买 nike

在 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"/>

其中amazonS3com.amazonaws.services.s3.AmazonS3 的 bean客户端。

关于java - 如何在使用出站网关上传文件之前检查 aws s3 存储桶是否可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51867049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com