According to their documentation, safeSearchDetection
accepts base64 encoded images but when I do that it throws an error:
No document found with that ID: Error: ENAMETOOLONG: name too long
const visionClient = new vision.ImageAnnotatorClient();
const data = await visionClient.safeSearchDetection(encoded_img);
const safeSearchResult = data[0].safeSearchAnnotation;
if (
safeSearchResult.adult !== 'VERY_UNLIKELY' ||
safeSearchResult.spoof !== 'VERY_UNLIKELY' ||
safeSearchResult.medical !== 'VERY_UNLIKELY' ||
safeSearchResult.violence !== 'VERY_UNLIKELY' ||
safeSearchResult.racy !== 'VERY_UNLIKELY'
) {
functions.logger.log('Offensive image found.');
}
What am I doing wrong here that I cant see?!
CodePudding user response:
From the documentation,
If the key (first param in
safeSearchDetection
) iscontent
(base64
string in this case), the value should be aBuffer
.
const imgBuffer = Buffer.from(encoded_img, "base64");
const data = await visionClient.safeSearchDetection(imgBuffer);