我如何使用base64编码的图像扫描在云功能明确的内容?



根据他们的文档,safeSearchDetection接受base64编码的图像,但当我这样做时,它会抛出一个错误:

没有找到具有该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.');
} 

我在这里做错了什么,我看不到?

从文档中

如果键(safeSearchDetection中的第一个参数)为content(本例中为base64字符串),则该值应为Buffer

const imgBuffer = Buffer.from(encoded_img, "base64");
const data = await visionClient.safeSearchDetection(imgBuffer);

最新更新