How to use Firebase storage image with Google Cloud Vision API?

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://MYAPP.appspot.com/photos/IMG_12345.jpg

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 and scope are optional if auth is not required.
    'clientId': MY_APP_ID + '.apps.googleusercontent.com',
    'scope': 'profile',
  }).then(function() {
    // 3. Initialize and make the API request.
    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);
+4
1

- Google (. ).

, API , ( , API , ?).

+1

Source: https://habr.com/ru/post/1665567/


All Articles