小编Mar*_*ärz的帖子

尝试从 Googl-Cloud-Storage 读取值导致无效授予

我试图从我的 Spring 应用程序中读取 Google-Cloud 存储中的值。我使用 Spring Cloud GCP 扩展来与 Google Cloud Storage 配合使用。我的 Pom.xml 用于 gcp 依赖项:

<dependency>
 <groupId>org.springframework.cloud</groupId>
 <artifactId>spring-cloud-gcp-starter-storage</artifactId> 
 <version>1.1.2.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

当我尝试从我的休息端点读取文件时,我得到一个异常(在我的答案末尾),不知何故我的令牌无法刷新?我可以在哪里设置我的 clientId 或者还有其他事情发生?我使用了由 Pivotal 和 google 提供的示例应用程序中的代码。

@RestController
public class GCloudStorageController {

    @Value("gs://test_files_test/test.txt")
    private Resource gcsFile;

    @RequestMapping(value = "/cloud", method = RequestMethod.GET)
    public String readGcsFile() throws IOException {
        return StreamUtils.copyToString(
                this.gcsFile.getInputStream(),
                Charset.defaultCharset()) + "\n";
    }

    @RequestMapping(value = "/cloud", method = RequestMethod.POST)
    String writeGcs(@RequestBody String data) throws IOException {
        try (OutputStream os = ((WritableResource) this.gcsFile).getOutputStream()) {
            os.write(data.getBytes());
        }
        return …
Run Code Online (Sandbox Code Playgroud)

java spring google-cloud-storage google-cloud-platform

4
推荐指数
1
解决办法
1604
查看次数