java - 如何为 gs 注册 URL 流处理程序 : protocol in Java Spring

标签 java spring-boot google-cloud-storage

我的代码必须能够处理“普通”网址,例如“file:///...”以及“gs://...”文件。

我有一个 application.yaml 文件,其中包含

bannedKeywordsFile:gs://myproject.appspot.com/mybucket/myfile.csv

此操作失败并出现 MalformedURLException。

@Value("${bannedKeywordsFile}")
private Resource bannedKeywordsFile;

private URL myUrl() {
    return bannedKeywordsFile.getURL();
}

公平地说,Google 文档解释说,除非注册了协议(protocol)处理程序,否则这是预期的情况。是否有可以注册的处理程序?或者必须从头开始编写?

最佳答案

一种可能是忽略 Google GCS“url”前缀并使用 HTTP 访问文件。例如:

gs://bucket/file

可以通过以下方式访问:

http://storage.googleapis.com/bucket/file

参见:

How do you get or generate a URL to the object in a bucket?

这基本上回避了gs://...视为特殊事物的原始概念。

关于java - 如何为 gs 注册 URL 流处理程序 : protocol in Java Spring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58491602/

相关文章:

java - 如何单独检索时间字段?

java - 界面设计问题: Storing Result of Transactions

java - java.util.Calendar 的默认时区是什么?

java - BigQuery - 如何在 Java 客户端库中设置读取超时

java - 确保在 Spring Boot 中 Web 服务器公开 HTTP 之前执行代码

api - 考虑在您的配置中定义类型为 'javax.servlet.ServletContext' 的 bean

java - Mongo 嵌入式服务器 : the single instance is not primary in replica set

typescript - 如何使用 Firebase Firestore 在客户端上缓存 getDownloadUrl() 调用?

google-cloud-platform - Google Cloud Platform 中的身份验证

php - 谷歌云存储的互操作访问授权请求失败,出现 'signature does not match' 错误