首页 > 解决方案 > s3 入站通道适配器中的本地目录表达式

问题描述

我可以在 s3 入站适配器中有本地目录表达式吗?我的本地目录路径是一个表达式。如何在本地目录属性中分配表达式变量?

Config details below                 
         <int-aws:s3-inbound-channel-adapter id="s3FileInbound"
                                         channel="s3FilesChannel" 
                                         session-factory="s3SessionFactory" 
                                         auto-create-local-directory="false"
                                         delete-remote-files="false" 
                                         preserve-timestamp="true"
                                         filter="acceptOnceFilter"
                                         local-directory="local_directory"
                                         auto-startup="false" 
                                         remote-directory="s3_bucket"/>

标签: spring-bootspring-integrationspring-integration-aws

解决方案


local-directory无法从消息中解决,因为消息是在将远程文件复制到该local-directory.

此属性可用于构建相对本地路径:

   <xsd:attribute name="local-filename-generator-expression">
                    <xsd:annotation>
                        <xsd:documentation>
                            Allows you to provide a SpEL expression to
                            generate the file name of
                            the local (transferred) file. The root
                            object of the SpEL
                            evaluation is the name of the original
                            file.
                            For example, a valid expression would be "#this.toUpperCase() +
                            '.a'" where #this represents the
                            original name of the remote
                            file.
                        </xsd:documentation>
                    </xsd:annotation>
                </xsd:attribute>

因此,您可以local-directory在硬盘驱动器上拥有一个根路径,并从那里构建一个目标目录以及本地文件系统的文件名。

另请参阅https://jira.spring.io/browse/INT-4025了解更多信息。

更新

我会这样配置它:

 <int-aws:s3-inbound-channel-adapter 
           local-directory="C:/"
           local-filename-generator-expression="'my_local_directory/' + #this"/>

推荐阅读