1

Can i have local-directory-expression in s3 inbound adapter. My local-directory path is an expression . How to assign expression variable in the local-directory attribute ?

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"/>
Las
  • 37
  • 4
  • Show that expression, please. – Artem Bilan Oct 23 '18 at 14:43
  • The local directory path will be received from integration channel header. For example, header.sourcedir like this. – Las Oct 23 '18 at 16:47
  • It’s not going to work that way: the message is created already after a copy to local directory. So, no such an info yet – Artem Bilan Oct 23 '18 at 16:50
  • You mean. We have to provide absolute path as local directory path during initialize. – Las Oct 23 '18 at 16:58
  • Right. Or it can be derived from some configuration property via properties placeholder. Another option is to consider as a file name expression where you can include some sub sir as well – Artem Bilan Oct 23 '18 at 17:00
  • Ok sure. Let me try this and will update the status – Las Oct 23 '18 at 17:06
  • Also see this JIRA for more possible solutions and how we plan to fix it: https://jira.spring.io/browse/INT-4025 – Artem Bilan Oct 23 '18 at 18:16
  • The above approach is OK but i am reading s3 bucket source directory and destination directory from the configuration file. As you mentioned above we can modify the destination path using file name expression but what about source location ?. – Las Oct 29 '18 at 09:29
  • What is my understanding, I will have to write five n number of S3 inbound adapters with respect to n number of buckets . am i right ? . if no , any other solution on this ? – Las Oct 29 '18 at 09:31

1 Answers1

0

The local-directory cannot be resolved from the message because message is created exactly after copying remote file to that local-directory.

This attribute can be used to build a relative local path:

   <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>

So, you can have a local-directory as a root path on your hard drive and build a target directory from there together with the file name for local file system.

Also see https://jira.spring.io/browse/INT-4025 for more info.

UPDATE

I would configure it like this:

 <int-aws:s3-inbound-channel-adapter 
           local-directory="C:/"
           local-filename-generator-expression="'my_local_directory/' + #this"/>
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Could you please share some sample codes on this solution mentioned above – Las Nov 05 '18 at 17:17
  • See an UPDATE in my answer. The problem that you even don't show your possible expression, so I don't know what is your intention. – Artem Bilan Nov 05 '18 at 18:48
  • Yes. My 'my_local_directory' is a dynamic path will be add run time from the .yaml file. It is configured in the Spring boot .yaml file. As discussed earlier we cannot add content in the header since message is created exactly after copying remote file to that local directory. In this case how to get path from .yaml file and add to the 'my_local_directory'. – Las Nov 06 '18 at 04:00
  • Huh? That is called Properties Placeholder: https://www.baeldung.com/properties-with-spring – Artem Bilan Nov 06 '18 at 04:38