我正在为学校项目创建一个微型应用程序。我正在使用 native 脚本 Playground ,这使得调试有点困难。我只想拍照并将其发送到自定义视觉 API 以预测图像是什么。我不确定如何正确设置带有图像的主体。
takePicture() {
camera
.takePicture({
width: 120,
height: 180,
keepAspectRatio: true
})
.then(imageAsset => {
this.pictureFromCamera = imageAsset;
http.request({
url: "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Prediction/key/image",
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
"Prediction-Key": "key"
},
content: JSON.stringify({
Body: imageAsset
})
}).then(
response => {
this.response = response.content.toJSON();
console.log("RESPONSE", this.response);
},
error => {
console.error("ERRRORR", error);
}
);
})
.catch(err => {
console.log("Error -> " + err.message);
});
}
}
这是记录的响应:
[Galaxy S8+]: 'RESPONSE' { code: [Getter/Setter],
[Galaxy S8+]: message: [Getter/Setter],
[Galaxy S8+]: { value: [Circular],
[Galaxy S8+]: [__ob__]:
[Galaxy S8+]: dep: { id: 39, subs: [Object] },
[Galaxy S8+]: vmCount: 0 } }
最佳答案
您不能将图像资源字符串化。发送多部分数据的唯一方法是使用 nativescript-background-http插件,默认的 http 模块不支持。
关于android - 如何在 nativescript-vue 中正确设置对 Microsoft 自定义视觉 API 的 http 调用主体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54433019/