更新时间:2023-11-27 09:19:46
您可以配置S3RemoteFileTemplate
bean,并在<filter>
中使用其exists()
API:
You can configure an S3RemoteFileTemplate
bean and use its exists()
API in the <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"/>
更新
面对异常
java.lang.IllegalStateException: 'path' must in pattern [BUCKET/KEY]
.
对不起,您错过了需要检查bucket
而不是内部对象的事实.
Sorry, missed the fact that you need to check existence of the bucket
, not an object inside.
为此,您需要直接使用Amazon API:
For that purpose you need to use an Amazon API directly:
<int:filter expression="@amazonS3.doesBucketExistV2(headers.TARGET_BUCKET)" throw-exception-on-rejection="true"/>
其中amazonS3
是com.amazonaws.services.s3.AmazonS3
客户端的bean.
where an amazonS3
is a bean for the com.amazonaws.services.s3.AmazonS3
client.