Search code examples
javaamazon-s3apache-camelapache-camel-aws

Keep the filename and filetype in AWS S3 upload using Camel


Being a beginner with AWS and S3, i was trying to integrate to upload a Sample.txt file from my local sftp to s3 using apache camel

<route>
        <from uri="sftp://testuser@localhost?password=test&amp;delete=true" />
        <setHeader name="CamelAwsS3Key">
            <constant>test</constant>
        </setHeader>
        <to uri="aws-s3://myTestBucket?accessKey=******&amp;secretKey=RAW(******)&amp;deleteAfterWrite=false&amp;region=AP_SOUTH_1" />
    </route>

This works but the file always uploads with the name test and type is also not shown. Have tried multiple methods. Any suggestions would be helpful.


Solution

  • The issue has been resolved when passing a the key and using the filename provided by SFTP simple

    <route>
            <from uri="sftp://testuser@localhost?password=test&amp;delete=true" />
            <setHeader name="CamelAwsS3Key">
                 <simple>${in.header.camelFileName}</simple>
            </setHeader>
            <to uri="aws-s3://myTestBucket?accessKey=******&amp;secretKey=RAW(******)&amp;deleteAfterWrite=false&amp;region=AP_SOUTH_1" />
        </route>
    

    Thanks to @gusto2 for the support.

    Also, as an addition you can add to a specific folder the file on upload by changing ,

    <simple>{foldername}/${in.header.camelFileName}</simple>