I am trying to read a file form google cloud storage using the following API, in a spring boot application:
GET https://storage.googleapis.com/storage/v1/b/bucket/o/object
This is my code:
@Component("GetObjFromGCP")
class GetObjFromGCP{
public void readFromFile() throws UnirestException{
HttpResponse<String> jsonResponse
= Unirest.get("https://storage.googleapis.com/storage/v1/b/sagessapp_test/o/apache%20camel%20notes.txt?alt=media")
.header("accept", "application/json")
.asString();
System.out.println(jsonResponse.getBody());
}
}
However I am getting this error:
Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.
I have a json file containing the service account credentials and the appropriate role to read files from my bucket.
the application.properties file:
spring.cloud.gcp.credentials.location=classpath:/gcp-credentials.json
So any idea how can I solve this error? Thank you