android - 如何在 nativescript-vue 中正确设置对 Microsoft 自定义视觉 API 的 http 调用主体?

标签 android vue.js nativescript azure-cognitive-services

我正在为学校项目创建一个微型应用程序。我正在使用 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/

相关文章:

android - Android GridView适配器崩溃

android - 如何从内部存储中读取文件内容 - Android 应用

javascript - 如何在 vue draggable 中保持拖动项目直到释放

javascript - Nativescript:逻辑控制sideDrawer

javascript - 然后在 nativescript 中获取后就无法工作

php - 检测从 Android 应用程序调用的 URL

java - Android DBFlow 一对多完整示例

javascript - 具有 CSS 动画和过渡效果的 Vue.js Todo 任务

typescript - Vue : TypeScript Error when using Vue. 混入

javascript - Lambda 未将 http 响应正文返回到 API 网关