Search code examples
google-cloud-platformgoogle-cloud-firestoregoogle-cloud-functionsgoogle-cloud-vision

Google Cloud Vision - How to pass image from my storage bucket if I only have its url?


I am running a cloud function which is triggered everytime a specific document on my firestore is created. This document has a public uri as field which refers to an image that has previosly been stored in my GCStorage bucket.

Looking at the Node.js example here, I can see that we have to provide the GCVision client the file's name to work with the API:

// Performs safe search detection on the local file
const [result] = await GCV.safeSearchDetection(fileName);
const detections = result.safeSearchAnnotation;
console.log("Safe search:");
console.log(`Adult: ${detections.adult}`);
console.log(`Medical: ${detections.medical}`);
console.log(`Spoof: ${detections.spoof}`);
console.log(`Violence: ${detections.violence}`);
console.log(`Racy: ${detections.racy}`);

But, what about if I only have a signed url?

const fileUrl = "https://storage.googleapis.com/my-project-191sa.appspot.com/images/imageName.jpg?GoogleAccessId=firebase-adminsdk-as2af%my-project-191sa.iam.gserviceaccount.com&Expires=4202444800&Signature=AXh..."

Do I have to parse the url and get imageName to work with the API? Or is there any other method to provide the signed url directly?


Solution

  • Okey, dumb question. If you pass the uri directly, it works.

    const [result] = await GCV.safeSearchDetection(imageUri);