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

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

问题描述

我有一个使用apache骆驼的休息api.当我在路线上遇到发帖请求时,它应该从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 Key标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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