javascript - 如何将图像从云功能请求发送到视觉 API?
问题描述
我刚刚设置了一个带有 http 端点的基本谷歌云功能。我想将图像传递到此端点并将其一直发送到视觉 api(已设置),然后将视觉 api 的响应发送回响应。
所以基本上:
image in POST request -> cloud-function -> vision api ->|
response of vision api <- cloud function <- vision api <-|
这是将图像发送到视觉 api 的基本代码:
const vision = require("@google-cloud/vision");
// Creates a client
const client = new vision.ImageAnnotatorClient();
const timeStart = new Date();
// Performs text detection on the local file
client
.textDetection(file)
.then(results => {
const detections = results[0].textAnnotations;
console.log("Text:");
detections.forEach(text => console.log(text));
const timeEnd = new Date();
console.log(timeEnd - timeStart);
})
.catch(err => {
console.error("ERROR:", err);
});
如何处理 POST 请求中的图像并将其发送到视觉 API?
谢谢!
解决方案
我会将图像放在谷歌云存储桶中,将对象公开,然后只将桶的名称/网址发送到视觉 API。
推荐阅读
- msbuild - 后期构建脚本
- javascript - 如何使用 javascript 在 html5 画布中绘制可滚动菜单?
- c# - 使用 ISerializable 会中断以前支持的类型的序列化
- java - 如何将 ArrayLists 类中的变量设置为 Main 类?
- actionscript-3 - AS3 中的随机百分比
- php - “Classlike 没有在任何地方定义或导入。” 关于非标准注释(例如@prepare、@access)
- php - 如何用 php 订购一个大的 csv 文件?
- c++-cli - 我如何需要更改文本文件中的数据类型才能读取字符串而不是整数(C++/CLI、OleDb)?
- angular - 从我的对象中获取正确的数据以执行角度求和
- flutter - 如何让 SliverPersistentHeader “过度生长”