在camel-spring boot应用程序中getObject操作返回元数据而不是来自GCP的对象内容

问题描述 投票:0回答:2

我有一个 Spring Boot 应用程序,使用 Camel 连接到 google 对象存储以获取对象(文本或照片)。 这是我正在运行的代码:

package footballRestAPIs;


import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.google.storage.GoogleCloudStorageConstants;
import org.springframework.stereotype.Component;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;

import core.ErrorProcessor;


@Component("ListObjFromGCP")
public class ListObjFromGCP extends RouteBuilder{
    
    
     @Override
        public void configure() throws Exception {
            
         
            onException(Exception.class).handled(true)
            .process(new ErrorProcessor());
            

            rest("/").produces("application.json") 
            .get("selectPhoto")
            
            .to("direct:selectPhoto");

        from("direct:selectPhoto")
        .process(new Processor() {
            @Override
            public void process(Exchange xchg) throws Exception {
                xchg.getIn().setHeader(GoogleCloudStorageConstants.OBJECT_NAME, "kitten.png");
                
            }
        })
        
        .to("google-storage://sagessapp_test?operation=getObject")
.log("${body}");

        }

}

在 aplication.properties 文件中,我有以下内容:

spring.cloud.gcp.credentials.location=classpath:/gcp-credentials.json
camel.component.google-storage.service-account-key=classpath:/gcp-credentials.json

这就是

.log("${body}")
显示的内容:

Blob{bucket=sagessapp_test, name=kitten.png, generation=1637310466399682, size=0, content-type=application/octet-stream, metadata=null}

在 blob 中我可以看到元数据,但我没有找到任何有关如何返回对象内容的文档。有什么建议么?预先感谢您!

java spring-boot google-cloud-platform apache-camel cloud-object-storage
2个回答
0
投票

默认返回对象元数据。

尝试使用

alt=media
参数返回对象数据:

默认情况下,这会在响应中使用对象资源进行响应 身体。如果您提供 URL 参数

alt=media
,那么它会响应 与响应正文中的对象数据。


0
投票

在查看了 Camel Google Storage 组件的源代码后,我了解到您必须将其用作消费者来检索实际的文件内容。

作为路线的一部分这样做,您使用 pollEnrich,所以

.pollEnrich(“google-storage://sagessapp_test?includeBody=true&objectName=kitten.png”)

© www.soinside.com 2019 - 2024. All rights reserved.