我有一个使用骆驼连接到谷歌对象存储来获取对象(文本或照片)的弹簧启动应用程序。这是我正在运行的代码:
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 中我可以看到元数据,我没有找到任何关于如何返回对象内容的文档。有什么建议么?先感谢您!