仅在 URI 中设置 AWS S3 密钥标头 [英] Set the AWS S3 Key header in the URI only

查看:30
本文介绍了仅在 URI 中设置 AWS S3 密钥标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 apache camel 的 rest api.当我在路由上点击 post 请求时,它应该从 S3 获取一个文件.我正在发送 json 数据(文件名、bucketName、accesskey、secretkey、region)以便从 s3 中提取文件.这是代码 ->

I have a rest api using apache camel. When I hit a post request on a route, it should get a file from S3. I am sending json data(filename, bucketName, accesskey, secretkey, region) in order to extract the file from s3. Here is the code for that ->

public static class HelloRoute extends RouteBuilder {
       
        @Override
        public void configure() {
            rest("/")
                .post("file-from-s3")
                    .route()
                    .setHeader(AWS2S3Constants.KEY, constant("filename"))
                    .to("aws2-s3://bucketnameaccessKey=INSERT&secretKey=INSERT&region=INSERT&operation=getObject")
                    .to("file:/tmp/")
               

问题是我不想要 .setHeader(AWS2S3Constants.KEY, constant("filename"))部分.有没有办法删除它并在 URI 本身中放置一个替代方法.我试过这样的 ->

The issue is that I don't want the .setHeader(AWS2S3Constants.KEY, constant("filename")) part. Is there a way to remove that and put an alternate to that in the URI itself. I tried something like this ->

public static class HelloRoute extends RouteBuilder {
       
        @Override
        public void configure() {
            rest("/")
                .post("file-from-s3")
                    .route()                 
                    .to("aws2-s3://bucketnameaccessKey=INSERT&secretKey=INSERT&region=INSERT&filename=hello.txt&operation=getObject")
                    .to("file:/tmp/")
               

但这给了我一个错误java.lang.IllegalArgumentException: AWS S3 Key header missing..有没有其他方法可以做到这一点?

But this is giving me an error java.lang.IllegalArgumentException: AWS S3 Key header missing.. Is there some other way to do this?

推荐答案

有时构建 AWS 请求可能很复杂,因为有多种选择.我们介绍了使用 POJO 作为主体的可能性.

Sometimes build an AWS Request can be complex, because of multiple options. We introduce the possibility to use a POJO as body.

看看:https://camel.apache.org/components/latest/aws2-s3-component.html#_using_a_pojo_as_body

这篇关于仅在 URI 中设置 AWS S3 密钥标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆