我的代码必须能够处理“普通”网址,例如“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/