使用 S3 出站网关将元数据数据添加到 S3 对象
Adding metadata data to S3 object using S3 outbound gateway
已为 spring 集成 aws 应用程序编写代码,该应用程序当前使用 s3-outbound-gateway 将文件从源文件夹上传到目标 S3 存储桶。想要在 S3 存储桶中上传文件时添加以下用户定义的元数据及其有关文件的值。
x-amz-meta-sourcePath : /test
x-amz-meta-targetPath :/targetbucket/
x-amz-meta-timestamp:(#timestamp 值)
想知道如何使用 S3 出站网关或其他方式添加元数据。任何 documentation/example/suggestion 都将有助于实现这一目标。
<util:map id="userMetadata" value-type="java.lang.String">
<entry key="x-amz-meta-source" value="testsource" />
<entry key="x-amz-meta-sourcePath" value="testpath" />
<entry key="x-amz-meta-targetPath" value="headers.TARGET_PATH" /> </util:map>
<bean id="objectMetadata" class="com.amazonaws.services.s3.model.ObjectMetadata">
<property name="userMetadata" ref="userMetadata"/>
</bean>
<bean id="uploadMetadataProvider" class="org.springframework.integration.aws.outbound.S3MessageHandler$UploadMetadataProvider">
<property name="objectMetadata" ref="objectMetadata"/>
</bean>
<int-aws:s3-outbound-gateway id="s3File"
request-channel="filesS3GateWay"
reply-channel="filesS3ChainChannel"
transfer-manager="transferManager"
bucket-expression = "headers.TARGET_PATH"
key-expression="headers.file_name"
upload-metadata-provider="uploadMetadataProvider"
command="UPLOAD">
<int-aws:request-handler-advice-chain>
<ref bean="retryAdvice" />
</int-aws:request-handler-advice-chain>
</int-aws:s3-outbound-gateway>
我想你需要的是这个:
<xsd:attribute name="upload-metadata-provider">
<xsd:annotation>
<xsd:documentation>
Reference to an instance of
'org.springframework.integration.aws.outbound.S3MessageHandler$UploadMetadataProvider'.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.integration.aws.outbound.S3MessageHandler$UploadMetadataProvider"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
所以,你注入这样一个 UploadMetadataProvider
:
/**
* The callback to populate an {@link ObjectMetadata} for upload operation.
* The message can be used as a metadata source.
*/
public interface UploadMetadataProvider {
void populateMetadata(ObjectMetadata metadata, Message<?> message);
}
然后根据请求消息将您需要的任何内容填充到 ObjectMetadata
中。
已为 spring 集成 aws 应用程序编写代码,该应用程序当前使用 s3-outbound-gateway 将文件从源文件夹上传到目标 S3 存储桶。想要在 S3 存储桶中上传文件时添加以下用户定义的元数据及其有关文件的值。
x-amz-meta-sourcePath : /test
x-amz-meta-targetPath :/targetbucket/
x-amz-meta-timestamp:(#timestamp 值)
想知道如何使用 S3 出站网关或其他方式添加元数据。任何 documentation/example/suggestion 都将有助于实现这一目标。
<util:map id="userMetadata" value-type="java.lang.String">
<entry key="x-amz-meta-source" value="testsource" />
<entry key="x-amz-meta-sourcePath" value="testpath" />
<entry key="x-amz-meta-targetPath" value="headers.TARGET_PATH" /> </util:map>
<bean id="objectMetadata" class="com.amazonaws.services.s3.model.ObjectMetadata">
<property name="userMetadata" ref="userMetadata"/>
</bean>
<bean id="uploadMetadataProvider" class="org.springframework.integration.aws.outbound.S3MessageHandler$UploadMetadataProvider">
<property name="objectMetadata" ref="objectMetadata"/>
</bean>
<int-aws:s3-outbound-gateway id="s3File"
request-channel="filesS3GateWay"
reply-channel="filesS3ChainChannel"
transfer-manager="transferManager"
bucket-expression = "headers.TARGET_PATH"
key-expression="headers.file_name"
upload-metadata-provider="uploadMetadataProvider"
command="UPLOAD">
<int-aws:request-handler-advice-chain>
<ref bean="retryAdvice" />
</int-aws:request-handler-advice-chain>
</int-aws:s3-outbound-gateway>
我想你需要的是这个:
<xsd:attribute name="upload-metadata-provider">
<xsd:annotation>
<xsd:documentation>
Reference to an instance of
'org.springframework.integration.aws.outbound.S3MessageHandler$UploadMetadataProvider'.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.integration.aws.outbound.S3MessageHandler$UploadMetadataProvider"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
所以,你注入这样一个 UploadMetadataProvider
:
/**
* The callback to populate an {@link ObjectMetadata} for upload operation.
* The message can be used as a metadata source.
*/
public interface UploadMetadataProvider {
void populateMetadata(ObjectMetadata metadata, Message<?> message);
}
然后根据请求消息将您需要的任何内容填充到 ObjectMetadata
中。