How to upload file to AWS S3 using Camel aws-s3 producer?

后端 未结 1 1946
你的背包
你的背包 2021-01-23 01:29

I\'m trying to upload a jpg file to AWS S3 bucket with Camel\'s aws-s3 producer. Can I make this work with this approach and if yes how? Now I\'m only getting an IOException and

相关标签:
1条回答
  • 2021-01-23 02:06

    I did some digging and found one solution. Route works if you convert file contents to byte array before passing it to the aws-s3 endpoint like this:

    from("file://src/data?fileName=file.jpg&noop=true&delay=15m")
        .convertBodyTo(byte[].class)
        .setHeader(S3Constants.CONTENT_LENGTH, simple("${in.header.CamelFileLength}"))
        .setHeader(S3Constants.KEY,simple("${in.header.CamelFileNameOnly}"))
        .to("aws-s3://{{awsS3BucketName}}"
                        + "?deleteAfterWrite=false&region=eu-west-1"
                        + "&accessKey={{awsAccessKey}}"
                        + "&secretKey=RAW({{awsAccessKeySecret}})")
        .log("done.");
    }
    

    There must also be S3Constants.CONTENT_LENGTH header value set to the file length in bytes.

    The solution above reads whole file to memory so it's not ideal to every situation. However the code above is also the most simple way that I know of using aws-s3 producer endpoint. I'm still happy to hear about other (and better) solutions.

    0 讨论(0)
提交回复
热议问题