首页 > 解决方案 > 将base64用于自定义视觉节点js

问题描述

目前我可以使用 url 作为我的分类图像 URL,但我想改用 base64string。但是当我尝试这样做时,我收到了 BadRequestImageFormat 错误消息。我能做些什么?

app.post('/predict', function(req, res){
const predictionKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const endPoint = "https://southcentralus.api.cognitive.microsoft.com"
const projectId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const publishedName = "AntiScam";
const PredictionApiClient = require("azure-cognitiveservices-customvision-prediction");
const predictor = new PredictionApiClient(predictionKey, endPoint);
var data2 = req.body.img;

tempData={ url: data2 };

predictor.classifyImageUrl(projectId, publishedName, tempData)
  .then((resultJSON) => {
       console.log("RESULT ######################")
       console.log(resultJSON);
             res.send(resultJSON);})

  .catch((error) => {
       console.log("ERROR #####################");
       console.log(error);}
);

});

标签: javascriptnode.jsazuremicrosoft-custom-vision

解决方案


请参阅此处的 API 定义:https ://southcentralus.dev.cognitive.microsoft.com/docs/services/Custom_Vision_Prediction_3.0/operations/5c82db60bf6a2b11a8247c15

唯一受支持的请求是multipart/form-data或者通过提供图像的 URL。所以不,似乎不支持 base64 字符串。


推荐阅读