【发布时间】:2021-05-14 13:44:59
【问题描述】:
我在这里找到了两篇类似的帖子,但一篇没有得到答复,另一篇是关于 android 的。我有一个 Spring Boot 项目,我想在我的应用程序中访问 GCP 存储文件。
在本地一切正常,我可以访问我的存储桶并在我的存储中读取和存储文件。但是当我将它上传到 gcp kubernetes 时,我得到了以下异常:
"java.nio.file.FileSystemNotFoundException: Provider "gs" not 安装在 java.nio.file.Paths.get(Paths.java:147) ~[na:1.8.0_212] 在 xx.xx.StorageService.saveFile(StorageService.java:64) ~[classes!/:0.3.20-SNAPSHOT]
我出现的代码行如下:
public void saveFile(MultipartFile multipartFile, String path) {
String completePath = filesBasePath + path;
Path filePath = Paths.get(URI.create(completePath)); // <- exception appears here
Files.createDirectories(filePath);
multipartFile.transferTo(filePath);
}
}
completePath 可能会导致类似“gs://my-storage/path/to/file/image.jpg”
我有以下依赖项:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-storage</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-nio</artifactId>
<version>0.122.5</version>
</dependency>
有人知道在哪里看吗? 除了基础设施之外,唯一真正的区别是我没有明确不在 kubernetes 上使用身份验证,因为根据文档,它不是必需的
从 Google Cloud Platform 使用 Google Cloud 库时 Compute Engine、Kubernetes Engine 或 App Engine 等环境, 无需额外的身份验证步骤。
【问题讨论】:
-
“本地一切正常”是指在容器内或本地机器上运行 Spring Boot 应用程序?
-
本地在我的机器上的eclipse
标签: java kubernetes google-cloud-storage nio spring-cloud-gcp