Question

reading file from google cloud storage

*
33 visibility 0 arrow_circle_up 0 arrow_circle_down

Using cloud Code i have created keys and added them in the Env. Now i am trying to read the bucket but it is not allowing me the read the content.

I am getting the below exception

java.io.FileNotFoundException: Could not open ServletContext resource [/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";
}

}