从Google云端存储读取文件

时间:2019-07-11 17:44:35

标签: spring google-cloud-platform

我使用云代码创建了密钥并将其添加到Env中。现在,我尝试读取存储桶,但不允许我读取内容。

我收到以下异常

java.io.FileNotFoundException:无法打开ServletContext资源[/gs://mybucket/my-file.txt]

@RestController
 public class Controller {

 @Value("gs://mybucket/my-file.txt")
private Resource gcsFile;



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

}

0 个答案:

没有答案