I have a webapp where users anonymously authenticate with Firebase Auth. I store images from users in Firebase Storage that are backstage supported by the Google Cloud Storage bucket. When I try to use the Google Cloud Vision API from client javascript to get image properties, I get a permission error.
image-annotator::User lacks permission.: Can not open file: gs:
If I make the image public, everything will work. But this is user data and may not be publicly available. How can i solve this?
My code to call api vision:
gapi.client.init({
'apiKey': MY_API_KEY,
'discoveryDocs': ['https://vision.googleapis.com/$discovery/rest'],
'clientId': MY_APP_ID + '.apps.googleusercontent.com',
'scope': 'profile',
}).then(function() {
return gapi.client.vision.images.annotate({
"requests":
[
{
"features":
[
{
"type": "LABEL_DETECTION"
},
{
"type": "IMAGE_PROPERTIES"
}
],
"image":
{
"source":
{
"gcsImageUri": "gs://MY_APP.appspot.com/photos/" + "IMG_12345.jpg"
}
}
}
]
});
}).then(function(response) {
console.log(response.result);
}, function(reason) {
console.log('Error: ' + reason.result.error.message);
});
My code for uploading images to storage:
var file = e.target.files[0];
var metadata = {
contentType: file.type
};
console.log(file);
var uploadTask = photosStorageRef.child(file.name).put(file, metadata);