firebase / firebase/codelab-friendlychat-web

Step 10 : Error: No image present. at _coerceRequest (/workspace/node_modules/@google-cloud/vision/build/src/helpers.js:54:25)

Open
#579 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.9k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

__Problem__
The code lab explanation uses "@google-cloud/vision@0.12.0", but the latest version of cloud vision api was 2.3.0

I proceeded as "https://codelabs.developers.google.com/codelabs/firebase-cloud-functions" explains, but I got an error below.
```
Step 10 : Error: No image present. at _coerceRequest (/workspace/node_modules/@google-cloud/vision/build/src/helpers.js:54:25)
```

__how to resolve__
Here's are the code I modified and I could finally got it!

Comment out line is the github code.
Not comment out line is the alternate code I wrote.

```
// const Vision = require("@google-cloud/vision");
// const vision = new Vision();
const vision = require("@google-cloud/vision");
const visionClient = new vision.ImageAnnotatorClient();

// const image = {
// source: { imageUri: `gs://${object.bucket}/${object.name}` },
// };
const request = {
image: {
source: { imageUri: `gs://${object.bucket}/${object.name}` },
},
};

// const batchAnnotateImagesResponse = await vision.safeSearchDetection(
// image
// );
// const safeSearchResult =
// batchAnnotateImagesResponse[0].safeSearchAnnotation;
// const Likelihood = visionClient.types.Likelihood;
// if (
// Likelihood[safeSearchResult.adult] >= Likelihood.LIKELY ||
// Likelihood[safeSearchResult.violence] >= Likelihood.LIKELY
// ) {
// console.log(
// "The image",
// object.name,
// "has been detected as inappropriate."
// );
// return blurImage(object.name);
// }
// console.log("The image", object.name, "has been detected as OK.");

visionClient
.safeSearchDetection(request)
.then((batchAnnotateImagesResponse) => {
safeSearchResult = batchAnnotateImagesResponse[0].safeSearchAnnotation;
const Likelihood = {
UNKNOWN: 0,
VERY_UNLIKELY: 1,
UNLIKELY: 2,
POSSIBLE: 3,
LIKELY: 4,
VERY_LIKELY: 5,
};
if (
Likelihood[safeSearchResult.adult] >= Likelihood.LIKELY ||
Likelihood[safeSearchResult.violence] >= Likelihood.LIKELY
) {
console.log(
"The image",
object.name,
"has been detected as inappropriate."
);
return blurImage(object.name);
}
console.log("The image", object.name, "has been detected as OK.");
})
.catch((err) => {
console.error(err);
});

```

I hope this help someone like me who will almost spend a lot of time to resolve this problem.

Contributor guide

Open the contributing guide

Research direction

Start with Step 10 of the Firebase Cloud Functions codelab and compare its @google-cloud/vision@0.12.0 usage with the alternate client code shown in the issue. Reproduce the “No image present” error, then verify the documented implementation works with the referenced Vision API version and safe-search response.

Written by the indexing model from the issue text.

Assessment

Tech stack
google-cloud, javascript, node.js
Domain
backend, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.